#include <bits/stdc++.h>
using namespace std;
const int N = (1e3) + 7, K = N * 2;
int n, k, p;
int a[N], b[K];
int res = 2e9, Max;
void _input() {
  cin >> n >> k >> p;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= k; ++i) cin >> b[i];
}
void _solve() {
  sort(a + 1, a + n + 1);
  sort(b + 1, b + k + 1);
  for (int i = 1; i <= k - n + 1; ++i) {
    Max = 0;
    for (int j = 1; j <= n; ++j)
      Max = max(Max, abs(a[j] - b[i + j - 1]) + abs(b[i + j - 1] - p));
    res = min(res, Max);
  }
}
void _output() { cout << res << '\n'; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    _input();
    _solve();
    _output();
  }
  return 0;
}
