#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 1e2;
long long n, k, p, bb;
long long a[maxn];
vector<int> b;
int main() {
  cin >> n >> k >> p;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < k; i++) {
    cin >> bb;
    b.push_back(bb);
  }
  sort(a, a + n);
  sort((b).begin(), (b).end());
  long long sum = 1e18;
  long long nuj;
  long long potr;
  for (long long i = 0; i + n <= k; i++) {
    potr = 0;
    for (long long j = 0; j < n; j++) {
      if (potr < (abs(b[i + j] - a[j])) + (abs(p - b[i + j]))) {
        nuj = j;
        potr = abs(b[i + j] - a[j]) + (abs(p - b[i + j]));
      }
    }
    sum = min(sum, potr);
  }
  cout << sum << endl;
  return 0;
}
