#include <bits/stdc++.h>
using namespace std;
const long long oo = (long long)1e18;
const int mod = (int)1e9 + 7;
const double PI = acos(-1.0);
const int MAX = 2003;
int n, m, p;
int a[MAX], b[MAX];
long long dp[MAX][MAX];
long long solve(int i, int j) {
  if (i >= n) return 0;
  if (j >= m) return oo;
  long long& r = dp[i][j];
  if (r != -1) return r;
  r = solve(i, j + 1);
  r = min(r, max(0LL + abs(a[i] - b[j]) + abs(b[j] - p), solve(i + 1, j + 1)));
  return r;
}
int main() {
  scanf("%d%d%d", &n, &m, &p);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < m; i++) {
    scanf("%d", &b[i]);
  }
  sort(a, a + n);
  sort(b, b + m);
  memset(dp, -1, sizeof dp);
  cout << solve(0, 0) << endl;
  return 0;
}
