#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3c3c3c3c;
const long long infl = 0x3c3c3c3c3c3c3c3c;
const int MAX_N = 1e3 + 9;
int n, k, p;
int a[MAX_N], b[MAX_N * 2];
bool isPossible(long long v) {
  for (int i = 0; i < k - n + 1; i++) {
    bool is = true;
    for (int j = 0; j < n; j++) {
      if (abs(a[j] - b[j + i]) + abs(p - b[j + i]) > v) {
        is = false;
        break;
      }
    }
    if (is) return true;
  }
  return false;
}
int main() {
  cin.tie(NULL);
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  cin >> n >> k >> p;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < k; i++) cin >> b[i];
  sort(b, b + k);
  long long l = -1, r = 2e9 + 9;
  while (l + 1 < r) {
    long long m = (l + r) / 2;
    if (isPossible(m))
      r = m;
    else
      l = m;
  }
  printf("%lld", r);
  return 0;
}
