#include <bits/stdc++.h>
using namespace std;
const double sn = 1e-6;
int n, k, p;
long long res = LLONG_MAX;
int arrn[1005];
int arrk[2005];
int main() {
  scanf("%d%d%d", &n, &k, &p);
  for (int i = 0; i < n; i++) scanf("%d", &arrn[i]);
  sort(arrn, arrn + n);
  for (int i = 0; i < k; i++) scanf("%d", &arrk[i]);
  sort(arrk, arrk + k);
  for (int i = 0; i <= k - n; i++) {
    long long t = 0;
    for (int j = i; j < n + i; j++) {
      t = max((long long)abs(arrk[j] - arrn[j - i]) + abs(arrk[j] - p), t);
    }
    res = min(res, t);
  }
  printf("%I64d\n", res);
  return 0;
}
