#include <bits/stdc++.h>
using namespace std;
int n, k, p;
int a[2222];
int b[2222];
int main() {
  cin >> n >> k >> p;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= k; i++) {
    cin >> b[i];
  }
  sort(b + 1, b + k + 1);
  int ans = 2e9;
  for (int i = 0; i <= k; i++) {
    if (i + n > k) break;
    int mx = 0;
    for (int j = 1; j <= n; j++) {
      int tmp = abs(a[j] - b[i + j]) + abs(b[i + j] - p);
      mx = max(tmp, mx);
    }
    ans = min(mx, ans);
  }
  cout << ans << endl;
  return 0;
}
