#include <bits/stdc++.h>
using namespace std;
class TaskD {
 public:
  int n, k, p;
  int a[1011];
  ;
  int b[2011];
  int sorted[2011];
  void solve(std::istream& in, std::ostream& out) {
    in >> n >> k >> p;
    for (int i = 0; i < n; i++) in >> a[i];
    for (int j = 0; j < k; j++) in >> b[j];
    comp c;
    c.p = p;
    sort(a, a + n, c);
    sort(b, b + k, c);
    long long l = 0, r = INT_MAX;
    long long res = 0;
    while (r >= l) {
      long long mid = (l + r) / 2;
      if (check(mid)) {
        res = mid;
        r = mid - 1;
      } else
        l = mid + 1;
    }
    out << res << endl;
  }
  int vst[2011];
  bool check(long long mid) {
    memset(vst, 0, sizeof vst);
    for (int i = 0; i < n; i++) {
      bool ok = 0;
      for (int j = 0; j < k; j++) {
        if (!vst[j]) {
          int dist = abs(a[i] - b[j]) + abs(b[j] - p);
          if (dist <= mid) {
            ok = 1;
            vst[j] = 1;
            break;
          }
        }
      }
      if (!ok) return 0;
    }
    return 1;
  }
  struct comp {
    int p;
    bool operator()(int x, int y) {
      int dist1 = abs(x - p);
      int dist2 = abs(y - p);
      return dist1 > dist2;
    }
  };
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  TaskD solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
