#include <bits/stdc++.h>
using namespace std;
vector<long long> num, position;
long long p;
int check(long long x) {
  int index = 0;
  for (int i = 0; i < num.size(); i++) {
    if (abs(num[i] - p) > x) return 0;
    int flag = 0;
    for (int j = index; j < position.size(); j++) {
      if (abs(num[i] - position[j]) + abs(position[j] - p) <= x) {
        flag = 1;
        index = j + 1;
        break;
      }
    }
    if (!flag) return 0;
  }
  return 1;
}
int main() {
  int n, k;
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> k >> p;
  long long t;
  for (int i = 0; i < n; i++) {
    cin >> t;
    num.push_back(t);
  }
  sort(num.begin(), num.end());
  for (int i = 0; i < k; i++) {
    cin >> t;
    position.push_back(t);
  }
  sort(position.begin(), position.end());
  long long r = max(max(position[k - 1], num[n - 1]), p) * 2;
  long long l = 0;
  while (r - l > 3) {
    long long mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  long long ans;
  for (long long i = l; i <= r; i++) {
    if (check(i)) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
