#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, p;
  cin >> n >> k >> p;
  vector<int> people(n);
  for (int& x : people) cin >> x;
  vector<int> keys(k);
  for (int& x : keys) cin >> x;
  sort(begin(people), end(people));
  sort(begin(keys), end(keys));
  int answer = numeric_limits<int>::max();
  for (int i = 0; i + n <= k; i++) {
    int option = 0;
    for (int j = 0; j < n; j++)
      option = max(option, abs(people[j] - keys[i + j]) + abs(keys[i + j] - p));
    answer = min(answer, option);
  }
  cout << answer << endl;
}
