#include <bits/stdc++.h>
using namespace std;
long long n, m, p, i, j, dp[3000][3000], inf = 10000000000, a[3000], b[3000],
                                         cost;
int main() {
  cin >> n >> m >> p;
  for (i = 1; i <= n; ++i) cin >> a[i];
  for (i = 1; i <= m; ++i) cin >> b[i];
  sort(a, a + n + 1);
  sort(b + 1, b + m + 1);
  for (i = 1; i <= n; ++i) {
    for (j = 0; j <= m; ++j) dp[i][j] = inf;
  }
  for (i = 1; i <= n; ++i) {
    for (j = i; j <= m; ++j) {
      cost = abs(a[i] - b[j]) + abs(p - b[j]);
      dp[i][j] = min(dp[i][j - 1], cost);
      dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);
    }
  }
  cout << dp[n][m];
  return 0;
}
