#include <bits/stdc++.h>
using namespace std;
const int N = 2048;
int n, k, p, a[N], b[N];
long long state[N][N];
bool used[N][N];
long long recurse(int posa, int posb) {
  if (posa > n) return 0;
  if (posb > k) return 1000000000000000000;
  if (used[posa][posb]) return state[posa][posb];
  long long ans = 1000000000000000000;
  ans = min(ans, recurse(posa, posb + 1));
  ans = min(ans, max(recurse(posa + 1, posb + 1),
                     abs(a[posa] - b[posb]) + 0ll + abs(b[posb] - p)));
  used[posa][posb] = true;
  state[posa][posb] = ans;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j;
  scanf("%d %d %d", &n, &k, &p);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (j = 1; j <= k; j++) scanf("%d", &b[j]);
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + k);
  printf("%lld\n", recurse(1, 1));
  return 0;
}
