#include <bits/stdc++.h>
using namespace std;
long long int n, k, nb, a[1005], b[2005], t = -10000, pos = 0, p, d;
long long int save[1005][2005];
long long int time(int i, int j) {
  if (save[i][j] != -1) return save[i][j];
  if (i == n) return 0;
  if (j == k) return 3e9;
  return (save[i][j] = min(time(i, j + 1), max(abs(a[i] - b[j]) + abs(p - b[j]),
                                               time(i + 1, j + 1))));
}
int main() {
  long long int i, j;
  cin >> n >> k >> p;
  vector<long long int> v;
  v.clear();
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (i = 0; i < k; i++) cin >> b[i];
  sort(b, b + k);
  memset(save, -1, sizeof save);
  t = time(0, 0);
  cout << t;
}
