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