#include <bits/stdc++.h>
using namespace std;
const long long N = 2222;
long long n, m, p, a[N], b[N], dp[N][N];
bool used[N][N];
long long rec(long long i, long long j) {
  if (used[i][j]) return dp[i][j];
  if (i == n) return 0;
  if (j == m) return 1e18;
  used[i][j] = 1;
  dp[i][j] = 1e18;
  dp[i][j] = min(max(rec(i + 1, j + 1), abs(a[i] - b[j]) + abs(p - b[j])),
                 rec(i, j + 1));
  return dp[i][j];
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> p;
  for (long long i = 0; i < n; ++i) cin >> a[i];
  for (long long i = 0; i < m; ++i) cin >> b[i];
  sort(a, a + n);
  sort(b, b + m);
  cout << rec(0, 0);
}
