#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, k, p;
  cin >> n >> k >> p;
  vector<long long> a(n), b(k);
  for (auto &i : a) cin >> i;
  for (auto &i : b) cin >> i;
  sort((a).begin(), (a).end());
  sort((b).begin(), (b).end());
  long long ans = 1e18;
  for (long long i = 0; i < (long long)(b).size() - (long long)(a).size() + 1;
       ++i) {
    long long res = 0;
    for (long long j = 0; j < (long long)(a).size(); ++j) {
      res = max(res, abs(a[j] - b[i + j]) + abs(b[i + j] - p));
    }
    ans = min(ans, res);
  }
  cout << ans;
}
