#include <bits/stdc++.h>   using namespace std;   vector<long long> per, obs;   long long n, k, p;   bool check(long long t) {     long long i = 0;     for (long long j = 0; j <= obs.size() - 1; j++) {       if (abs(per[i] - obs[j]) + abs(p - obs[j]) <= t) {         i++;         if (i == n) return 1;       }     }     return 0;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     t = 1;     for (long long test = 1; test <= t; test++) {       cin >> n >> k >> p;       per.resize(n);       obs.resize(k);       for (long long i = 0; i <= n - 1; i++) cin >> per[i];       for (long long i = 0; i <= k - 1; i++) cin >> obs[i];       sort(per.begin(), per.end());       sort(obs.begin(), obs.end());       long long ans = 1e10, st = 0, end = 1e10;       while (st <= end) {         long long mid = (st + end) >> 1;         if (check(mid)) {           ans = min(ans, mid);           end = mid - 1;         } else           st = mid + 1;       }       cout << ans;     }     return 0;   }   