#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, p, k;
  cin >> n >> m >> p;
  int i, j, b[m + 5], v[m + 5], a[n + 5];
  for (i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  for (i = 1; i <= m; i++) cin >> b[i];
  sort(b + 1, b + 1 + m);
  long long int t = 0, w = 2000000000, mid, f, ff;
  while (t < w) {
    mid = (t + w) / 2;
    ff = 0;
    k = 1;
    for (i = 1; i <= n; i++) {
      f = 0;
      for (j = k; j <= m; j++) {
        if (abs(a[i] - b[j]) + abs(b[j] - p) <= mid) {
          f = 1;
          break;
        }
      }
      if (f == 0) {
        ff = 1;
        break;
      } else {
        k = j + 1;
      }
    }
    if (ff == 0)
      w = mid;
    else
      t = mid + 1;
  }
  cout << t << endl;
  return 0;
}
