#include <bits/stdc++.h>
using namespace std;
int n, k, p, ans;
int a[2050], b[2050];
int f[2050][2050];
inline int read() {
  int s = 0, w = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') w = -1;
  for (; isdigit(c); c = getchar()) s = (s << 1) + (s << 3) + (c ^ 48);
  return s * w;
}
int main() {
  n = read(), k = read(), p = read();
  for (register int i = 1; i <= n; i++) a[i] = read();
  sort(a + 1, a + n + 1);
  for (register int i = 1; i <= k; i++) b[i] = read();
  sort(b + 1, b + k + 1);
  for (register int i = 1; i <= n; i++) {
    f[i][i - 1] = 2e9;
    for (register int j = i; j <= k - (n - i); j++)
      f[i][j] = min(f[i][j - 1],
                    max(f[i - 1][j - 1], abs(a[i] - b[j]) + abs(b[j] - p)));
  }
  printf("%d", f[n][k]);
  return 0;
}
