#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int SZ = 2000 + 10;
LL g_n, g_k, g_p;
LL a[SZ], b[SZ];
void prete() {}
void input() {
  for (int i = 0; i < g_n; ++i) {
    scanf(" %I64d", a + i);
  }
  for (int i = 0; i < g_k; ++i) {
    scanf(" %I64d", b + i);
  }
}
void solve() {
  LL ans = LLONG_MAX;
  sort(a, a + g_n);
  sort(b, b + g_k);
  for (int i = 0; i <= g_k - g_n; ++i) {
    LL t = LLONG_MIN;
    for (int j = 0; j < g_n; ++j) {
      t = max(t, abs(a[j] - b[i + j]) + abs(b[i + j] - g_p));
    }
    ans = min(ans, t);
  }
  cout << ans << endl;
}
int main() {
  prete();
  while (cin >> g_n >> g_k >> g_p) {
    input();
    solve();
  }
  return 0;
}
