#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int A[N], pos[N];
int n, k, p, ans;
int abs(int k) { return max(k, -k); }
int main() {
  scanf("%d%d%d", &n, &k, &p);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  for (int i = 1; i <= k; i++) scanf("%d", &pos[i]);
  sort(A + 1, A + n + 1);
  sort(pos + 1, pos + k + 1);
  ans = (int)(2 * 1e9);
  for (int i = 0; i <= k - n; i++) {
    int cur = 0;
    for (int j = 1; j <= n; j++)
      cur = max(cur, abs(A[j] - pos[i + j]) + abs(p - pos[i + j]));
    ans = min(ans, cur);
  }
  cout << ans << endl;
}
