#include <bits/stdc++.h>
using namespace std;
long long person[2020], key[2020];
long long dp[2020][2020], n, k, path;
long long func(int perid, int keid) {
  if (perid == n) return 0;
  if (keid == k) return 1e15;
  long long &ret = dp[perid][keid];
  if (ret != -1) return ret;
  ret = 1e15;
  ret = min(ret, max(llabs(person[perid] - key[keid]) + llabs(key[keid] - path),
                     func(perid + 1, keid + 1)));
  ret = min(ret, func(perid, keid + 1));
  return ret;
}
int main() {
  int i, j;
  cin >> n >> k >> path;
  for (i = 0; i < n; i++) cin >> person[i];
  for (i = 0; i < k; i++) cin >> key[i];
  sort(person, person + n);
  sort(key, key + k);
  memset(dp, -1, sizeof dp);
  cout << func(0, 0) << endl;
  return 0;
}
