#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void solve() {
  long long n, k, p;
  cin >> n >> k >> p;
  vector<long long> a(n);
  vector<long long> b(k);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < k; i++) cin >> b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  long long ans = 1e14;
  for (int i = 0; i < k - n + 1; i++) {
    long long time = 0;
    for (int j = 0; j < n; j++) {
      time = max(time, abs(a[j] - b[i + j]) + abs(p - b[j + i]));
    }
    ans = min(ans, time);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tests = 1;
  while (tests--) {
    solve();
  }
}
