#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
long long pow(long long a, long long b, long long M) {
  long long t = 1;
  for (a %= M; b; b >>= 1) {
    if (b & 1) t = t * a % M;
    a = a * a % M;
  }
  return t;
}
const int N = 2005;
int n, m, p, a[N], b[N];
int main() {
  cin >> n >> m >> p;
  for (int i = 1; i <= int(n); i++) scanf("%d", &a[i]);
  for (int i = 1; i <= int(m); i++) scanf("%d", &b[i]);
  sort(a + 1, a + n + 1);
  sort(b + 1, b + m + 1);
  int ans = 2e9;
  for (int i = 1; i <= int(m - n + 1); i++) {
    int rem = 0;
    for (int j = 1; j <= int(n); j++)
      rem = max(rem, abs(a[j] - b[i + j - 1]) + abs(b[i + j - 1] - p));
    ans = min(ans, rem);
  }
  cout << ans;
}
