#include <bits/stdc++.h>
using namespace std;
const int nmax = 2000;
const int inf = 1 << 30;
int a[nmax + 1], b[nmax + 1];
int main() {
  int n, m, p;
  cin.sync_with_stdio(false);
  cin >> n >> m >> p;
  int ind1 = 0, ind2 = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    ind1 += (a[i] <= p);
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= m; ++i) {
    cin >> b[i];
    ind2 += (b[i] <= p);
  }
  sort(b + 1, b + m + 1);
  int ans = inf - 1 + inf;
  for (int i = 1; i <= m - n + 1; ++i) {
    int sol = 0;
    for (int j = 1; j <= n; ++j) {
      sol = max(sol, abs(a[j] - b[i + j - 1]) + abs(b[i + j - 1] - p));
    }
    ans = min(ans, sol);
  }
  cout << ans << "\n";
  return 0;
}
