#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const int maxn = 2000 + 10;
int k[maxn], r[maxn];
int nk, nr, pos;
int dp[maxn][maxn];
int main() {
  scanf("%d%d%d", &nr, &nk, &pos);
  for (int i = 1; i <= nr; i++) scanf("%d", &r[i]);
  for (int i = 1; i <= nk; i++) scanf("%d", &k[i]);
  sort(r + 1, r + nr + 1);
  sort(k + 1, k + 1 + nk);
  for (int i = 0; i <= nr; i++) fill(dp[i], dp[i] + nr + 1, inf);
  fill(dp[0], dp[0] + nk + 1, 0);
  for (int i = 1; i <= nr; i++)
    for (int j = i; j <= nk; j++) {
      int d = abs(r[i] - k[j]) + abs(k[j] - pos);
      dp[i][j] = min(dp[i][j - 1], max(dp[i - 1][j - 1], d));
    }
  printf("%d\n", dp[nr][nk]);
  return 0;
}
