#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10240000")
using namespace std;
const int MAXN = 2020;
const long long MAX_INF = (long long)1 << 50;
long long a[MAXN], b[MAXN], dp[MAXN][MAXN];
int main() {
  int n, m;
  long long p;
  scanf("%d%d%I64d", &n, &m, &p);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%I64d", &b[i]);
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + m + 1);
  for (int i = 0; i <= m; i++) {
    dp[0][i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    dp[i][i] = max(dp[i - 1][i - 1], abs(b[i] - a[i]) + abs(p - b[i]));
    for (int j = i + 1; j <= m; j++) {
      dp[i][j] = dp[i][j - 1];
      if (max(dp[i - 1][j - 1], abs(b[j] - a[i]) + abs(p - b[j])) < dp[i][j]) {
        dp[i][j] = max(dp[i - 1][j - 1], abs(b[j] - a[i]) + abs(p - b[j]));
      }
    }
  }
  long long ans = MAX_INF;
  for (int j = n; j <= m; j++) {
    if (dp[n][j] < ans) {
      ans = dp[n][j];
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
