#include <bits/stdc++.h>
using namespace std;
int n, m, p, a[1001], b[2001];
int ans = 2147483647;
int main() {
  cin >> n >> m >> p;
  for (register int i = 0; i < n; i++) cin >> a[i];
  for (register int i = 0; i < m; i++) cin >> b[i];
  sort(a, a + n);
  sort(b, b + m);
  for (register int i = 0; i <= m - n; i++) {
    int t = 0;
    for (register int j = 0; j < n; j++)
      t = max(t, abs(a[j] - b[i + j]) + abs(p - b[i + j]));
    ans = min(ans, t);
  }
  cout << ans << endl;
  return 0;
}
