#include <bits/stdc++.h>
using namespace std;
long long ans;
const int maxn = 2020;
long long people[maxn];
long long key[maxn];
long long dp[maxn][maxn];
int main() {
  int p, k, h;
  scanf("%d%d%d", &p, &k, &h);
  for (int i = 1; i <= p; i++) scanf("%d", &people[i]);
  sort(people + 1, people + 1 + p);
  for (int i = 1; i <= k; i++) scanf("%d", &key[i]);
  sort(key + 1, key + 1 + k);
  for (int i = 1; i <= p; i++) {
    dp[i][0] = 2e9 + 7;
    for (int j = 1; j <= k; j++) {
      dp[i][j] =
          max(abs(key[j] - people[i]) + abs(key[j] - h), dp[i - 1][j - 1]);
    }
    for (int j = 1; j <= k; j++) {
      dp[i][j] = min(dp[i][j], dp[i][j - 1]);
    }
  }
  printf("%lld", dp[p][k]);
  return 0;
}
