#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;
long long n, k, p;
const long long INF = (long long)1e18 + 10;
VI pos, keys;
long long minTime() {
  sort(keys.begin(), keys.end());
  sort(pos.begin(), pos.end());
  long long ans = INF;
  for (int delta = 0; delta <= k - n; ++delta) {
    long long dist = -INF;
    for (int i = 0; i < n; ++i)
      dist =
          max(dist, abs(pos[i] - keys[i + delta]) + abs(keys[i + delta] - p));
    ans = min(ans, dist);
  }
  return ans;
}
const int MAXN = 2010;
long long DP[MAXN][MAXN];
long long solve(int i, int j) {
  if (i == n) return 0;
  if (j == k) return INF;
  long long& ret = DP[i][j];
  if (ret != -1) return ret;
  ret = INF;
  long long dist = 1ll * abs(pos[i] - keys[j]) + abs(keys[j] - p);
  ret = max(dist, solve(i + 1, j + 1));
  ret = min(ret, solve(i, j + 1));
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k >> p;
  pos.assign(n, 0);
  keys.assign(k, 0);
  for (int i = 0; i < (int)n; ++i) cin >> pos[i];
  for (int i = 0; i < (int)k; ++i) cin >> keys[i];
  memset(DP, -1, sizeof(DP));
  sort(pos.begin(), pos.end());
  sort(keys.begin(), keys.end());
  cout << solve(0, 0) << endl;
  return 0;
}
