#include <bits/stdc++.h>
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi pair<int, int>
#define f first
#define s second
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, t;
cin >> n >> t;
vector<int> a(n);
vector<int> tp;
for (int i = 0; i < n; ++i) {
cin >> a[i];
tp.push_back(a[i] % t);
}
sort(all(tp));
int res = 1e18;
int mm = tp[0], mxx = tp.back();
res = min(res, (mxx - mm + 1) / 2);
for (int i = 0; i < (int)tp.size() - 1; ++i) {
int mx = tp[i];
mm = tp[i + 1];
res = min(res, (mx + t - mm + 1) / 2);
}
cout << res << "\n";
}