#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500000;
const int SUPERN = 5000000;
const int MAXS = 325;
const int SUPERS = 1000;
const int MD = 1e9 + 7;
long long n, k, a[MAXN], b[MAXN], p, mx, mn;
long long sum(long long a, long long b) { return (a + b) % MD; }
long long mu(long long a, long long b) { return (a * b) % MD; }
long long mon(long long a, long long b) { return (a - b + MD) % MD; }
int main() {
  mn = 1e18;
  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);
  for (int i = 0; i <= k - n; ++i) {
    mx = 0;
    for (int j = 1; j <= n; ++j) {
      mx = max(mx, abs(a[j] - b[i + j]) + abs(b[i + j] - p));
    }
    mn = min(mn, mx);
  }
  cout << mn;
  return 0;
}
