#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const int INF = 0x3f3f3f3f;
int n, k, p;
int A[N], B[N];
int main() {
  while (~scanf("%d %d %d", &n, &k, &p)) {
    for (int i = 0; i < n; ++i) scanf("%d", &A[i]);
    sort(A, A + n);
    for (int i = 0; i < k; ++i) scanf("%d", &B[i]);
    sort(B, B + k);
    int ans = 2e9;
    for (int i = 0; i < k - n + 1; ++i) {
      int tmp = -1;
      for (int j = 0; j < n; ++j) {
        tmp = max(tmp, abs(A[j] - B[i + j]) + abs(p - B[i + j]));
      }
      ans = min(ans, tmp);
    }
    printf("%d\n", ans);
  }
  return 0;
}
