#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int N = 2005;
int n, k, p, a[N], b[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k >> p;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= k; i++) cin >> b[i];
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + k);
  int sol = 2000000000 + 10;
  for (int i = 1; i <= k - n + 1; i++) {
    int mx = -1;
    for (int j = i; j <= i + n - 1; j++) {
      mx = max(mx, abs(b[j] - a[j - i + 1]) + abs(b[j] - p));
    }
    sol = min(sol, mx);
  }
  cout << sol;
  return 0;
}
