#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
const long long int INF = 1e18;
int read() {
  int x = 0;
  char ch = getchar();
  while ('0' > ch || ch > '9') ch = getchar();
  while ('0' <= ch && ch <= '9') {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return x;
}
int n, k;
long long int p;
long long int a[N], b[N];
long long int ans;
int vis[N];
int solve(long long int x) {
  memset(vis, 0, sizeof(vis));
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      if (vis[j]) continue;
      if (abs(a[i] - b[j]) + abs(p - b[j]) <= x) {
        vis[j] = 1;
        cnt++;
        break;
      }
    }
  }
  if (cnt == n) return 1;
  return 0;
}
int main() {
  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 int l = 0;
  long long int r = 1e10;
  ans = 0;
  while (r - l >= 0) {
    long long int mid = (r + l) >> 1;
    if (solve(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << endl;
}
