#include <bits/stdc++.h>
using namespace std;
long long int n, k, p, dp[1010][2010], ar[1010], br[2010];
int main() {
  scanf("%lld%lld%lld", &n, &k, &p);
  for (int i = 1; i <= n; i++) scanf("%lld", &ar[i]);
  for (int i = 1; i <= k; i++) scanf("%lld", &br[i]);
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= k; j++) dp[i][j] = 1e12;
  sort(ar + 1, ar + n + 1);
  sort(br + 1, br + k + 1);
  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(br[j] - ar[i]) + abs(p - br[j])));
  printf("%lld\n", dp[n][k]);
}
