#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
const long long INF = 1e17;
int a[N], b[N];
long long dp[N][N];
int main() {
  int n, m, p;
  cin >> n >> m >> p;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= m; ++i) cin >> b[i];
  sort(a + 1, a + n + 1), sort(b + 1, b + m + 1);
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= m; ++j) {
      dp[i][j] =
          max(dp[i - 1][j - 1], (long long)(abs(a[i] - b[j])) + abs(b[j] - p));
      if (j - 1 >= i) dp[i][j] = min(dp[i][j], dp[i][j - 1]);
    }
  }
  long long ans = INF;
  for (int j = n; j <= m; ++j) ans = min(ans, dp[n][j]);
  cout << ans << endl;
}
