#include <bits/stdc++.h>
using namespace std;
int n, k, p;
int man[1005];
int key[2005];
int dis[1005][2005];
int dp[1005][2005];
inline int cmp(int a, int b) { return a < b; }
int minn(int a, int b) {
  if (a >= b) return b;
  return a;
}
int maxx(int a, int b) {
  if (a >= b) return a;
  return b;
}
int main() {
  cin >> n >> k >> p;
  for (register int i = 1; i <= n; i++) {
    cin >> man[i];
  }
  for (register int i = 1; i <= k; i++) {
    cin >> key[i];
  }
  sort(man + 1, man + n + 1, cmp);
  sort(key + 1, key + k + 1, cmp);
  for (register int i = 0; i <= n; i++) {
    for (register int j = 0; j <= k; j++) {
      dis[i][j] = fabs(man[i] - key[j]) + fabs(key[j] - p);
      dp[i][j] = 2147483647;
    }
  }
  for (register int i = 0; i <= k; i++) {
    dp[0][i] = 0;
  }
  for (register int i = 1; i <= n; i++) {
    for (register int j = 1; j <= k; j++) {
      dp[i][j] = minn(dp[i][j - 1], maxx(dp[i - 1][j - 1], dis[i][j]));
    }
  }
  int ans = 2147483647;
  for (register int i = n; i <= k; i++) {
    ans = min(ans, dp[n][i]);
  }
  cout << ans << endl;
}
