#include <bits/stdc++.h>
using namespace std;
struct edge {
  long long a, b, cost;
  edge(long long x, long long y, long long z) : a(x), b(y), cost(z){};
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, k, p;
  cin >> n >> k >> p;
  vector<long long> v(n), a(k);
  for (long long i = 0; i < (long long)(n); i++) cin >> v[i];
  for (long long i = 0; i < (long long)(k); i++) cin >> a[i];
  sort((v).begin(), (v).end());
  sort((a).begin(), (a).end());
  long long ans = INT_MAX;
  for (long long i = (long long)(0); i <= (long long)(k - n); i++) {
    long long res = INT_MIN;
    for (long long j = (long long)(0); j <= (long long)(n - 1); j++) {
      res = max(res, abs(v[j] - a[i + j]) + abs(a[i + j] - p));
    }
    ans = min(ans, res);
  }
  cout << ans << endl;
  return 0;
}
