#include <bits/stdc++.h>
using namespace std;
inline void smax(long long &x, long long y) { x = max(x, y); }
inline void smin(long long &x, long long y) { x = min(x, y); }
inline long long in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%I64d", &x);
  return x;
}
inline void out(long long x) { printf("%d ", x); }
inline void lout(long long x) { printf("%I64d ", x); }
const long long MOD = 1e9 + 7;
const long double EPS = 1e-9;
const long long INF = 1e9 + 10;
const long long LINF = 1e18;
const long long N = 1e3 + 10;
const long long maxn = 1e4 + 10;
const long long MAXN = 1e5 + 10;
const long long MN = 1e6 + 10;
inline long long powmod(long long x, long long y) {
  long long res = 1, a = x;
  while (y) {
    if (y & 1) res = (res * a) % MOD;
    a = (a * a) % MOD;
    y >>= 1;
  }
  return res;
}
long long n, k, p, f[2 * N], a[N], b[2 * N], ans = LINF, t[N][2 * N];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> k >> p;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  for (long long i = 1; i <= k; i++) cin >> b[i];
  sort(a + 1, a + n + 1);
  sort(b + 1, b + k + 1);
  for (long long i = 1; i <= k; i++) f[i] = abs(b[i] - p);
  for (long long i = 1; i <= n; i++) {
    t[i][i] = max(t[i - 1][i - 1], abs(a[i] - b[i]) + f[i]);
    for (long long j = i + 1; j <= k; j++) {
      t[i][j] = t[i][j - 1];
      smin(t[i][j], max(abs(a[i] - b[j]) + f[j], t[i - 1][j - 1]));
    }
  }
  for (long long i = n; i <= k; i++) smin(ans, t[n][i]);
  cout << ans;
}
