#include <bits/stdc++.h>
using namespace std;
int x[1000], y[2000];
int main() {
  int n, k, p;
  scanf("%d%d%d", &n, &k, &p);
  for (int i = 0; i < (int)(n); ++i) scanf("%d", x + i);
  sort(x, x + n);
  for (int i = 0; i < (int)(k); ++i) scanf("%d", y + i);
  sort(y, y + k);
  int an = 2e9;
  for (int i = 0; i < (int)(k - n + 1); ++i) {
    int a = 0;
    for (int j = 0; j < (int)(n); ++j)
      a = max(a, abs(p - y[i + j]) + abs(y[i + j] - x[j]));
    an = min(an, a);
  }
  printf("%d\n", an);
}
