#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
int main() {
  int n, k, p;
  cin >> n >> k >> p;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> key(k);
  for (int i = 0; i < k; i++) cin >> key[i];
  sort(a.begin(), a.end());
  sort(key.begin(), key.end());
  int ans = INF;
  for (int i = 0; i < key.size() - a.size() + 1; i++) {
    int cur_d = -1;
    for (int j = 0; j < a.size(); j++) {
      int d = abs(key[i + j] - a[j]) + abs(key[i + j] - p);
      cur_d = max(cur_d, d);
    }
    ans = min(ans, cur_d);
  }
  cout << ans << endl;
}
