#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int qq = 2000 + 10;
long long pl[qq], kl[qq];
long long n, k, p;
pair<long long, long long> node[qq];
bool Check(long long x) {
  for (int i = 0; i < n; ++i) {
    if (x < abs(p - pl[i])) return false;
    long long dis = (x - abs(p - pl[i])) / 2;
    long long l = p, r = pl[i];
    if (l > r) swap(l, r);
    l -= dis;
    r += dis;
    node[i] = make_pair(l, r);
  }
  sort(node, node + n);
  int cur = 0;
  for (int i = 0; i < n; ++i) {
    while (cur < k && kl[cur] < node[i].first) cur++;
    if (cur < k && kl[cur] <= node[i].second)
      cur++;
    else
      return false;
  }
  return true;
}
int main() {
  scanf("%lld%lld%lld", &n, &k, &p);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", pl + i);
  }
  sort(pl, pl + n);
  for (int i = 0; i < k; ++i) {
    scanf("%lld", kl + i);
  }
  sort(kl, kl + k);
  long long l = 0, r = 1e18, mid;
  long long ans;
  while (l <= r) {
    mid = (l + r) / 2;
    if (Check(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
