#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;
const int MAXN = 1010, MAXK = 2020;
int n, k, office, DP[MAXN][MAXK];
VI people, keys;
int minTime(int i, int j) {
  if (i > n) return 0;
  if (j > k) return INT_MAX;
  int& ret = DP[i][j];
  if (ret != -1) return ret;
  int dist = abs(people[i] - keys[j]) + abs(keys[j] - office);
  ret = max(dist, minTime(i + 1, j + 1));
  ret = min(ret, minTime(i, j + 1));
  return ret;
}
int minTime() {
  sort(keys.begin(), keys.end());
  sort(people.begin(), people.end());
  int ret = INT_MAX;
  for (int start = 1; start <= k - n + 1; ++start) {
    int mx = INT_MIN;
    for (int i = 1; i <= n; ++i) {
      int dist = abs(people[i] - keys[i + start - 1]) +
                 abs(keys[i + start - 1] - office);
      mx = max(mx, dist);
    }
    ret = min(ret, mx);
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k >> office;
  people.resize(n + 1);
  for (int i = 1; i <= (int)n; ++i) cin >> people[i];
  keys.resize(k + 1);
  for (int i = 1; i <= (int)k; ++i) cin >> keys[i];
  memset(DP, -1, sizeof(DP));
  sort(keys.begin(), keys.end());
  sort(people.begin(), people.end());
  cout << minTime(1, 1) << endl;
  return 0;
}
