#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15 + 5;
const int len = 2005;
int n, k;
long long loc;
long long dp[len][len], arr[len], keys[len];
long long solve(int pos, int cur) {
  if (cur == k) {
    if (pos == n)
      return 0LL;
    else
      return inf;
  }
  if (dp[pos][cur] != -1) return dp[pos][cur];
  dp[pos][cur] = min(solve(pos, cur + 1),
                     max(solve(pos + 1, cur + 1),
                         abs(loc - keys[cur]) + abs(keys[cur] - arr[pos])));
  return dp[pos][cur];
}
int main() {
  scanf("%d %d %lld", &n, &k, &loc);
  for (int i = 0; i < n; i++) scanf("%lld", &arr[i]);
  for (int i = 0; i < k; i++) scanf("%lld", &keys[i]);
  sort(arr, arr + n);
  sort(keys, keys + k);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < k; j++) dp[i][j] = -1LL;
  printf("%lld\n", solve(0, 0));
  return 0;
}
