#include <bits/stdc++.h>
using namespace std;
const long long inf = 100000000 + 9;
int main(int argc, char** argv) {
  long long n, k, p;
  cin >> n >> k >> p;
  vector<long long> a(n, 0), b(k, 0);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < k; i++) cin >> b[i];
  sort(b.begin(), b.end());
  sort(a.begin(), a.end());
  long long mintime = inf;
  for (long long i = 0; i <= k - n; i++) {
    long long time = 0;
    for (long long j = 0; j < n; j++) {
      if (j != 0)
        time = max(time, abs(b[i + j] - a[j]) + abs(p - b[i + j]));
      else
        time = abs(b[i + j] - a[j]) + abs(p - b[i + j]);
    }
    if (i != 0)
      mintime = min(mintime, time);
    else
      mintime = time;
  }
  cout << mintime << endl;
  return 0;
}
