#include <bits/stdc++.h>
using namespace std;
const int maxn = 2020;
int n, k, p;
int dp[maxn][maxn];
int a[maxn], key[maxn];
int main() {
  scanf("%d %d %d", &n, &k, &p);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= k; ++i) scanf("%d", &key[i]);
  sort(a + 1, a + 1 + n);
  sort(key + 1, key + 1 + k);
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= k; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (i == j)
        dp[i][j] = max(dp[i - 1][j - 1], abs(a[j] - key[i]) + abs(p - key[i]));
      else
        dp[i][j] = min(dp[i - 1][j], max(dp[i - 1][j - 1],
                                         abs(a[j] - key[i]) + abs(p - key[i])));
    }
  }
  printf("%d", dp[k][n]);
  return 0;
}
