#include <bits/stdc++.h>
using namespace std;
long long dp[2010][2010];
int a[2010], b[2010], n, m, p;
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;
}
long long len(int i, int j) { return abs(a[i] - b[j]) + abs(p - b[j]); }
int main() {
  n = read(), m = read(), p = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1; i <= m; ++i) b[i] = read();
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + m);
  dp[0][0] = 0;
  for (int i = 1; i <= n; ++i) {
    dp[i][i] = max(dp[i - 1][i - 1], len(i, i));
    for (int j = i + 1; j <= m - n + i; ++j)
      dp[i][j] = min(dp[i][j - 1], max(dp[i - 1][j - 1], len(i, j)));
  }
  printf("%lld\n", dp[n][m]);
  return 0;
}
