#include <bits/stdc++.h>
using namespace std;
int const lim = 2004;
pair<int, int> people[lim + 3], keys[lim];
int n, k, office;
long long diss(long long x, long long y) {
  if (office >= x) {
    if (y >= x)
      if (y <= office)
        return office - x;
      else
        return y - x + y - office;
    else
      return x - y + office - y;
  } else {
    if (y <= x)
      if (y >= office)
        return x - office;
      else
        return x - y + office - y;
    else
      return y - x + y - office;
  }
}
bool check(long long x) {
  bool vis[2003] = {0};
  for (int i = n - 1; i >= 0; i--) {
    int dis = people[i].first;
    int pos = people[i].second;
    bool shit = false;
    for (int j = k - 1; j >= 0; j--)
      if (!vis[j] && diss(pos, keys[j].second) <= x) {
        vis[j] = true, shit = true;
        break;
      }
    if (!shit) return false;
  }
  return true;
}
int main() {
  cin >> n >> k >> office;
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    people[i] = make_pair(abs(x - office), x);
  }
  for (int i = 0; i < k; i++) {
    int x;
    scanf("%d", &x);
    keys[i] = make_pair(abs(x - office), x);
  }
  sort(people, people + n);
  sort(keys, keys + k);
  long long l = 0, r = 2e9 + 5;
  while (l < r) {
    if (l == r - 1) {
      if (check(l)) r = l;
      break;
    }
    long long mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << r << endl;
}
