#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a < b; }
int dp[1005][2005];
int a[1005], b[2005];
int main() {
  int n, k, p;
  while (scanf("%d %d %d", &n, &k, &p) != EOF) {
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= k; i++) scanf("%d", &b[i]);
    sort(a + 1, a + n + 1, cmp);
    sort(b + 1, b + k + 1, cmp);
    for (int i = 1; i <= n; i++) {
      for (int j = i; j <= k; j++) {
        if (j == i)
          dp[i][j] = max(dp[i - 1][j - 1], abs(a[i] - b[j]) + abs(b[j] - p));
        else
          dp[i][j] = min(dp[i][j - 1], max(dp[i - 1][j - 1],
                                           abs(a[i] - b[j]) + abs(b[j] - p)));
      }
    }
    int ans = 2000000000;
    for (int i = n; i <= k; i++) {
      ans = min(ans, dp[n][i]);
    }
    printf("%d\n", ans);
  }
}
