#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000 * 1000 * 1000 * 2 + 7;
int main() {
  long long n, k, p;
  cin >> n >> k >> p;
  vector<long long> a(n), b(k);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < k; i++) {
    cin >> b[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  long long ans = MAX;
  for (int l = 0; l < k - n + 1; l++) {
    long long cur = -1;
    for (int j = 0; j < n; j++) {
      long long t = b[l + j];
      if (a[j] < p) {
        if (a[j] <= t && t <= p) {
          if (cur == -1 || cur < p - a[j]) {
            cur = abs(p - a[j]);
          }
        } else if (a[j] > t) {
          if (cur == -1 || cur < abs(p - a[j]) + 2 * (a[j] - t)) {
            cur = abs(p - a[j]) + 2 * (a[j] - t);
          }
        } else if (t > p) {
          if (cur == -1 || cur < abs(p - a[j]) + 2 * (t - p)) {
            cur = abs(p - a[j]) + 2 * (t - p);
          }
        }
      } else {
        if (p <= t && t <= a[j]) {
          if (cur == -1 || cur < a[j] - p) {
            cur = a[j] - p;
          }
        } else if (t < p) {
          if (cur == -1 || cur < a[j] - p + 2 * (p - t)) {
            cur = a[j] - p + 2 * (p - t);
          }
        } else if (t > a[j]) {
          if (cur == -1 || cur < a[j] - p + 2 * (t - a[j])) {
            cur = a[j] - p + 2 * (t - a[j]);
          }
        }
      }
    }
    if (cur < ans) {
      ans = cur;
    }
  }
  cout << ans << endl;
}
