#include <bits/stdc++.h>
using namespace std;
int res = INT_MAX, n, k, p, a[1001], b[2001];
int main() {
  cin >> n >> k >> p;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int j = 0; j < k; ++j) cin >> b[j];
  sort(a, a + n);
  sort(b, b + k);
  for (int i = 0; i <= k - n; ++i) {
    int t = 0;
    for (int j = 0; j < n; ++j) {
      t = max(t, abs(a[j] - b[j + i]) + abs(p - b[i + j]));
    }
    res = min(res, t);
  }
  cout << res;
  return 0;
}
