#include <bits/stdc++.h>
using namespace std;
long long solve(int i, int j, vector<long long>& people,
                vector<long long>& keys, vector<vector<long long>>& dp,
                long long pos) {
  if (i == people.size()) return 0;
  if (j == keys.size()) return 1e17;
  if (dp[i][j] != -1) return dp[i][j];
  long long op1 = solve(i + 1, j + 1, people, keys, dp, pos);
  op1 = max(op1, (abs(keys[j] - people[i]) + abs(pos - keys[j])));
  long long op2 = solve(i, j + 1, people, keys, dp, pos);
  dp[i][j] = min(op1, op2);
  return dp[i][j];
}
int main() {
  long long n, k, p;
  cin >> n >> k >> p;
  vector<long long> people(n);
  vector<long long> keys(k);
  for (int i = 0; i < n; i++) cin >> people[i];
  for (int i = 0; i < k; i++) cin >> keys[i];
  sort(keys.begin(), keys.end());
  sort(people.begin(), people.end());
  vector<vector<long long>> dp(n + 1, vector<long long>(k + 1, -1));
  long long ans = solve(0, 0, people, keys, dp, p);
  cout << ans << endl;
}
