#include <bits/stdc++.h>
using namespace std;
int n, m;
int ans;
int a[2002], b[2002];
int le;
int p;
int ssearch(int x) {
  int maxd = 0;
  for (int i = 1; i <= n; i++) {
    int z = abs(a[i] - b[x - le + i]) + abs(b[x - le + i] - p);
    if (z > maxd) maxd = z;
  }
  return maxd;
}
int main() {
  int k;
  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", &b[i]);
  }
  sort(a + 1, a + 1 + n);
  sort(b + 1, b + 1 + k);
  le = n;
  for (int i = 1; i <= n; i++)
    if (a[i] >= p) {
      le = i - 1;
      break;
    }
  ans = 2147483647;
  for (int i = le; i <= k + le - n; i++) {
    int y = ssearch(i);
    if (y < ans) ans = y;
  }
  printf("%d\n", ans);
  return 0;
}
