#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, p;
  cin >> n >> k >> p;
  long long a[n], b[k];
  vector<long long> v;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < k; i++) cin >> b[i];
  sort(a, a + n);
  sort(b, b + k);
  long long ma;
  for (long long i = 0; i < k - n + 1; i++) {
    ma = -10;
    for (long long j = 0; j < n; j++) {
      ma = max(ma, abs(a[j] - b[j + i]) + abs(p - b[j + i]));
    }
    v.push_back(ma);
  }
  sort((v).begin(), (v).end());
  cout << v[0];
}
