#include <bits/stdc++.h>
using namespace std;
long long n, k, p;
long long a[1001], b[2001];
bool ok[2001];
long long tinh(long long a, long long b) { return abs(a - b) + abs(p - b); }
signed main() {
  cin >> n >> k >> p;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < k; i++) cin >> b[i];
  sort(a, a + n);
  sort(b, b + k);
  long long ans = 0;
  long long minn = 1e18;
  for (long long i = 0; i < k - n + 1; i++) {
    ans = 0;
    for (long long j = 0; j < n; j++) {
      ans = max(ans, tinh(a[j], b[i + j]));
    }
    minn = min(ans, minn);
  }
  cout << minn;
}
