#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const long long int INF = 1e14;
void Compute(long long int n, long long int k, long long int p) {
  vector<long long int> ar(n), br(k);
  vector<vector<long long int> > dp(n + 1, vector<long long int>(k + 1));
  for (long long int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (long long int i = 0; i < k; i++) {
    cin >> br[i];
  }
  sort(ar.begin(), ar.end());
  sort(br.begin(), br.end());
  for (long long int i = 0; i < n; i++) {
    dp[i][k] = INF;
  }
  for (long long int j = 0; j < k + 1; j++) {
    long long int mn = INF;
    for (long long int itr = j; itr < k; itr++) {
      long long int tmp = llabs(ar[n - 1] - br[j]) + llabs(br[j] - p);
      mn = min(mn, tmp);
    }
    dp[n - 1][j] = mn;
  }
  for (long long int i = n - 2; i >= 0; i--) {
    for (long long int j = k - 1; j >= 0; j--) {
      dp[i][j] = min(dp[i][j + 1], max(dp[i + 1][j + 1], llabs(ar[i] - br[j]) +
                                                             llabs(p - br[j])));
    }
  }
  cout << dp[0][0] << "\n";
}
int main() {
  long long int n, k, p;
  cin >> n >> k >> p;
  Compute(n, k, p);
}
