#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, p;
  scanf("%d%d%d", &n, &k, &p);
  vector<int> pos(n), s(k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &pos[i]);
  }
  for (int i = 0; i < k; i++) {
    scanf("%d", &s[i]);
  }
  sort(pos.begin(), pos.end());
  sort(s.begin(), s.end());
  long long ans = 1e18;
  for (int i = 0; i <= k - n; i++) {
    long long mx = 0;
    for (int j = 0; j < n; j++) {
      long long time1 = abs(pos[j] - s[i + j]);
      long long time2 = abs(s[i + j] - p);
      mx = max(mx, (long long)time1 + time2);
    }
    ans = min(mx, ans);
  }
  cout << ans << endl;
}
