#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  long long p;
  cin >> p;
  long long keys[2001], people[1001];
  for (int i = 0; i < n; i++) cin >> people[i];
  for (int i = 0; i < k; i++) cin >> keys[i];
  sort(keys, keys + k);
  sort(people, people + n);
  long long fin = 3e9;
  for (int i = 0; i + n <= k; i++) {
    long long ans = -1;
    for (int j = 0; j < n; j++)
      ans = max(ans, abs(people[j] - keys[i + j]) + abs(keys[i + j] - p));
    fin = min(fin, ans);
  }
  cout << fin << endl;
}
