#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  long long n, k, p;
  cin >> n >> k >> p;
  vector<long long> people;
  vector<long long> keys;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    people.push_back(x);
  }
  sort(people.begin(), people.end());
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    keys.push_back(x);
  }
  sort(keys.begin(), keys.end());
  long long ats = LLONG_MAX;
  for (int i = 0; i + n <= k; i++) {
    long long c = 0;
    for (int j = 0; j < n; j++)
      c = max(c, abs(people[j] - keys[i + j]) + abs(keys[i + j] - p));
    ats = min(c, ats);
  }
  cout << ats;
  return 0;
}
