#include <bits/stdc++.h>
using namespace std;
int n, m;
long long h[100004], p[100004];
bool ok(long long move) {
  int s = 1, news = 1;
  for (int i = 1; i <= n; i++) {
    s = news;
    if (h[i] - p[s] > move) return false;
    long long have = move;
    if (h[i] >= p[s]) {
      int tem1, tem2;
      have -= h[i] - p[s];
      for (int j = s + 1; j <= m + 1; j++) {
        if (j == m + 1) return true;
        if (p[j] <= h[i]) continue;
        if (p[j] - p[s] > have) {
          tem1 = j;
          break;
        }
      }
      for (int j = s + 1; j <= m + 1; j++) {
        if (j == m + 1) return true;
        if (p[j] > h[i] && (p[j] - h[i]) * 2 > have) {
          tem2 = j;
          break;
        }
      }
      news = max(tem1, tem2);
    } else {
      for (int j = s; j <= m + 1; j++) {
        if (j == m + 1) return true;
        if (p[j] - h[i] > have) {
          news = j;
          break;
        }
      }
    }
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) cin >> h[i];
  for (int i = 1; i <= m; i++) cin >> p[i];
  long long left = -1, right = 1LL << 38;
  while (left + 1 < right) {
    long long mid = (left + right) / 2;
    if (ok(mid))
      right = mid;
    else
      left = mid;
  }
  cout << right << "\n";
  return 0;
}
