#include <bits/stdc++.h>
using namespace std;
long long abs1(long long x) {
  if (x < 0) {
    return -x;
  }
  return x;
}
int main() {
  long long n, k, p, i, j, answer = 0, answer2 = 1e18, cnt, places[10005],
                           keys[10005];
  cin >> n >> k >> p;
  for (i = 0; i < n; i++) {
    cin >> places[i];
  }
  for (i = 0; i < k; i++) {
    cin >> keys[i];
  }
  sort(places, places + n);
  sort(keys, keys + k);
  for (i = 0; i <= k - n; i++) {
    answer = 0;
    cnt = 0;
    for (j = i; j < (i + n); j++) {
      answer = max(answer, (abs1(places[cnt] - keys[j]) + abs1(keys[j] - p)));
      ;
      cnt++;
    }
    answer2 = min(answer2, answer);
  }
  cout << answer2;
}
