#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long N = 1e5 + 10;
const long long mod = 1e9 + 7;
const long long INF = 1e18;
const long long inf = -1e18;
const long long M = 5 * 1e8;
long long a[1100], b[2100], n, k, p, co, color[2100];
long long check(long long t) {
  long long h, s;
  co++;
  for (int i = 1; i <= n; i++) {
    int f = 0;
    for (int j = 1; j <= k; j++) {
      if (color[j] != co) {
        s = abs(a[i] - b[j]) + abs(b[j] - p);
        if (s <= t) {
          f = 1;
          color[j] = co;
          break;
        }
      }
    }
    if (f == 0) return 0;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  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 = 0ll, r = 20000000000ll;
  while (l + 1 < r) {
    long long mid = ((l + r) >> 1);
    if (check(mid) == 1)
      r = mid;
    else
      l = mid;
  }
  if (check(l) == 1) {
    cout << l;
  } else {
    cout << r;
  }
  cin.get(), cin.get();
  return 0;
}
