#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 1e3 + 2;
long long dp[2 * MAX_N], memo[2 * MAX_N];
long long c[2 * MAX_N];
long long v[MAX_N], x[2 * MAX_N];
int n, k;
long long p;
int main() {
  cin >> n >> k >> p;
  for (int i = 1; i <= n; i++) cin >> v[i];
  for (int i = 1; i <= k; i++) cin >> x[i];
  sort(v + 1, v + n + 1);
  sort(x + 1, x + k + 1);
  for (int i = 1; i <= k; i++) c[i] = abs(x[i] - p);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) dp[j] = memo[j];
    for (int j = i; j <= k; j++)
      dp[j] = max(memo[j - 1], abs(v[i] - x[j]) + c[j]);
    memo[i] = dp[i];
    for (int j = i + 1; j <= k; j++) memo[j] = min(memo[j - 1], dp[j]);
  }
  cout << memo[k] << endl;
}
