#include <bits/stdc++.h>
using namespace std;
int const MAX = 1e5 + 5;
long long const INF = 1e11 + 5;
long long h[MAX], p[MAX];
bool vis[MAX];
int n, m;
bool ok(long long x) {
  memset(vis, false, sizeof(vis));
  int cur = 0;
  long long dis = 0;
  for (int i = 0; i < n; i++) {
    if (h[i] <= p[cur])
      dis = h[i] + x;
    else {
      if (x < (h[i] - p[cur])) return false;
      dis = max(p[cur] + x - (h[i] - p[cur]), h[i] + (x - (h[i] - p[cur])) / 2);
    }
    int idx;
    for (int j = cur; j < m; j++) {
      if (p[j] <= dis)
        vis[j] = true;
      else {
        idx = j;
        break;
      }
    }
    if (vis[m - 1]) return true;
    cur = idx;
  }
  return false;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%I64d", &h[i]);
  for (int i = 0; i < m; i++) scanf("%I64d", &p[i]);
  long long l = 0, r = INF, mid, ans;
  while (l <= r) {
    mid = (l + r) >> 1;
    if (ok(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  printf("%I64d\n", ans);
}
