#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
int n, k, p;
long long a[N], b[N];
bool check(long long x) {
  int lc = 0;
  for (int i = 1; i <= n; i++) {
    bool fp = false;
    while (lc <= k) {
      ++lc;
      long long tmp = abs(a[i] - b[lc]) + abs(b[lc] - p);
      if (tmp <= x) break;
    }
    if (lc > k) return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k >> p;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= k; i++) cin >> b[i];
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + k);
  long long l = 0, r = 2e9, ans;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (check(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  cout << ans << '\n';
}
