#include <bits/stdc++.h>
using namespace std;
int per[5000], key[5000];
long long dp[5000][5000];
int n, m, l;
long long solve(int p, int k) {
  if (p == n) return 0;
  if (k == m) return 10000000000100;
  if (dp[p][k] != -1) return dp[p][k];
  return dp[p][k] = min(solve(p, k + 1),
                        max((long long)abs(l - key[k]) + abs(per[p] - key[k]),
                            solve(p + 1, k + 1)));
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  scanf("%d", &l);
  for (int i = 0; i < n; ++i) scanf("%d", &per[i]);
  for (int i = 0; i < m; ++i) scanf("%d", &key[i]);
  memset(dp, -1, sizeof(dp));
  sort(per, per + n);
  sort(key, key + m);
  long long ans = solve(0, 0);
  printf("%lld", ans);
  return 0;
}
