#include <bits/stdc++.h>
using namespace std;
int n, k, p, as[1005], bs[2005], ans = 2147483647;
int main() {
  scanf("%d%d%d", &n, &k, &p);
  for (int i = 0; i < n; i++) scanf("%d", &as[i]);
  for (int i = 0; i < k; i++) scanf("%d", &bs[i]);
  sort(as, as + n);
  sort(bs, bs + k);
  for (int i = 0; i <= k - n; i++) {
    int temp = 0;
    for (int j = 0; j < n; j++)
      temp = max(temp, abs(as[j] - bs[i + j]) + abs(p - bs[i + j]));
    ans = min(temp, ans);
  }
  cout << ans;
  return 0;
}
