#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100000 + 10;
long long n, m, h[maxn], p[maxn], vis[maxn];
bool check(long long mid) {
  memset(vis, 0, sizeof(vis));
  long long opt = 1;
  for (long long i = 1; i <= n; i++) {
    long long r;
    if (p[opt] >= h[i]) {
      r = h[i] + mid;
    } else {
      r = max(p[opt] + (mid - (h[i] - p[opt])),
              (mid + p[opt] - h[i]) / 2 + h[i]);
      if (h[i] - p[opt] > mid) return 0;
    }
    while (opt <= m && p[opt] <= r) {
      vis[opt] = 1;
      opt++;
    }
    if (opt == m + 1) break;
  }
  for (long long i = 1; i <= m; i++)
    if (!vis[i]) return 0;
  return 1;
}
int main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> h[i];
  for (long long i = 1; i <= m; i++) cin >> p[i];
  long long l = 0, r = 21000000000, ans = 0;
  while (l <= r) {
    long long mid = (l + r) / 2;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
