#include <bits/stdc++.h>
using namespace std;
int a[2005], b[2005];
int main() {
  std::ios::sync_with_stdio(false);
  int n, k, p;
  long long minn = (1000 * 1000 * 1000 + 5);
  minn *= (1000 * 1000 * 1000 + 7);
  long long ans;
  int j, val, i;
  cin >> n >> k >> p;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < k; i++) {
    cin >> b[i];
  }
  sort(a, a + n);
  sort(b, b + k);
  for (i = 0; i < k - n + 1; i++) {
    val = 0;
    ans = 0;
    for (j = i; j < i + n; j++) {
      if ((b[j] >= a[val] && b[j] <= p) || (a[val] >= b[j] && b[j] >= p)) {
        ans = max(ans, (long long)abs(a[val] - p));
      } else {
        ans = max(ans, (long long)abs(b[j] - a[val]) + abs(p - b[j]));
      }
      val++;
    }
    minn = min(minn, ans);
  }
  cout << minn << endl;
}
