#include <bits/stdc++.h>
using namespace std;
long long dp[1001][2001], location;
int main() {
  int aa, bb;
  cin >> aa >> bb >> location;
  long long a[aa + 1], b[bb + 1];
  a[0] = 0;
  b[0] = 0;
  for (int z = 1; z <= aa; z++) {
    cin >> a[z];
  }
  for (int z = 1; z <= bb; z++) {
    cin >> b[z];
  }
  sort(a, a + (aa + 1));
  sort(b, b + (bb + 1));
  for (int z = 1; z <= aa; z++) {
    long long one = (max(a[z], b[z]) - min(a[z], b[z])) +
                    (max(location, b[z]) - min(location, b[z]));
    dp[z][z] = max(dp[z - 1][z - 1], one);
    for (int y = z + 1; y <= bb; y++) {
      one = (max(a[z], b[y]) - min(a[z], b[y])) +
            (max(location, b[y]) - min(location, b[y]));
      dp[z][y] = min(dp[z][y - 1], max(dp[z - 1][y - 1], one));
    }
  }
  cout << dp[aa][bb];
  return 0;
}
