#include <bits/stdc++.h>
using namespace std;
const long long inf = (1ll << 60);
int n, k, p;
int a[2005], b[2005];
long long dp[2005][2005];
long long rec(int pos, int key) {
  if (pos == n) {
    return 0;
  }
  if (key == k) return inf;
  long long &ret = dp[pos][key];
  if (ret != -1) return ret;
  long long sum = abs(a[pos] - b[key]) + abs(b[key] - p);
  ret = max(sum, rec(pos + 1, key + 1));
  ret = min(ret, rec(pos, key + 1));
  return ret;
}
int main() {
  cin >> n >> k >> p;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < k; i++) cin >> b[i];
  sort(a, a + n);
  sort(b, b + k);
  memset(dp, -1, sizeof dp);
  cout << rec(0, 0) << endl;
  return 0;
}
