#include <bits/stdc++.h>
using namespace std;
long long a[1005];
long long key[2005];
long long dp[1005][2005];
int main() {
  int n, k, p;
  while (cin >> n >> k >> p) {
    for (int i = 1; i <= n; ++i) {
      scanf("%d", a + i);
    }
    for (int j = 1; j <= k; ++j) {
      scanf("%d", key + j);
    }
    sort(a + 1, a + 1 + n);
    sort(key + 1, key + k + 1);
    memset(dp, 0xf, sizeof(dp));
    for (int i = 0; i <= k; ++i) dp[0][i] = 0;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= k; ++j) {
        dp[i][j] = min(dp[i][j - 1], max(dp[i - 1][j - 1],
                                         abs(a[i] - key[j]) + abs(key[j] - p)));
      }
    }
    printf("%lld\n", dp[n][k]);
  }
  return 0;
}
