#include <bits/stdc++.h>
using namespace std;
int n, k, p;
int a[1111], b[2222];
int main() {
  cin >> n >> k >> p;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= k; i++) {
    cin >> b[i];
  }
  int ans = 2e9;
  sort(a + 1, a + n + 1);
  sort(b + 1, b + k + 1);
  for (int i = 1; i <= k - n + 1; i++) {
    int cnt = 0;
    for (int j = 1; j <= n; j++) {
      cnt = max(cnt, abs(a[j] - b[i + j - 1]) + abs(p - b[i + j - 1]));
    }
    ans = min(ans, cnt);
  }
  cout << ans;
  return 0;
}
