#include <bits/stdc++.h>
inline int digitsIn(long long int n) {
  int ans = 0;
  while (n) {
    n /= 10;
    ans++;
  }
  return ans;
}
using namespace std;
int nh, nt, o;
long long int h[100005], t[100005];
int check(long long int m) {
  long long int r;
  int a = 0;
  for (int i = 0; i < nh; i++) {
    long long int d = abs(h[i] - t[a]);
    if (d > m && h[i] > t[a]) {
      return 0;
    }
    if (h[i] <= t[a]) {
      while (a < nt) {
        if (h[i] + m >= t[a])
          a++;
        else
          break;
      }
    } else {
      while (a < nt) {
        if (h[i] >= t[a])
          a++;
        else
          break;
      }
      r = max((m - d) / 2, m - 2 * d);
      while ((t[a] - h[i]) <= r && a < nt) {
        a++;
      }
    }
    if (a == nt) break;
  }
  if (a == nt) {
    return 1;
  } else {
    return 0;
  }
}
int main() {
  long long int low = 0LL, high = 10000000000000005LL, mid, answer = -1LL;
  cin >> nh >> nt;
  for (int i = 0; i < nh; i++) cin >> h[i];
  for (int i = 0; i < nt; i++) cin >> t[i];
  while (low <= high) {
    mid = (low + high) / 2;
    int result = check(mid);
    if (result) {
      high = mid - 1;
      answer = mid;
    } else {
      low = mid + 1;
    }
  }
  cout << answer << endl;
}
