#include <bits/stdc++.h>
using namespace std;
const int mn = 2010;
long long a[mn], b[mn];
int main() {
  int n, k;
  long long p;
  scanf("%d %d %lld", &n, &k, &p);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 1; i <= k; i++) scanf("%lld", &b[i]);
  sort(a + 1, a + n + 1);
  sort(b + 1, b + k + 1);
  long long ans = 4e18;
  for (int st = 0; st + n <= k; st++) {
    long long tans = 0;
    for (int i = 1; i <= n; i++) {
      long long temp = 0;
      long long now = b[st + i];
      if (a[i] <= p && now <= p) {
        if (a[i] <= now)
          temp += p - a[i];
        else
          temp += a[i] - now + p - now;
      } else if (a[i] <= p && p < now)
        temp += now - a[i] + now - p;
      else if (now <= p && p < a[i])
        temp += a[i] - now + p - now;
      else if (p < a[i] && p < now) {
        if (now <= a[i])
          temp += a[i] - p;
        else
          temp += now - a[i] + now - p;
      }
      tans = max(tans, temp);
    }
    ans = min(ans, tans);
  }
  printf("%lld\n", ans);
  return 0;
}
