#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const int maxm = 2005;
int a[maxn], b[maxm], n, k, p;
bool check(int now) {
  int pos, i;
  for (i = 1, pos = 0; i <= n; i++) {
    while (pos <= k) {
      pos++;
      if (abs(a[i] - b[pos]) + abs(b[pos] - p) <= now) break;
    }
    if (pos > k) return false;
  }
  return true;
}
int main() {
  scanf("%d%d%d", &n, &k, &p);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= k; i++) scanf("%d", b + i);
  sort(a + 1, a + n + 1);
  sort(b + 1, b + k + 1);
  int l = 0, r = 2e9, mid;
  while (l < r) {
    mid = (int)(((long long)l + r) >> 1);
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
  return 0;
}
