#include <bits/stdc++.h>
using namespace std;
long long int head[100005];
vector<long long int> track;
int n, mm;
inline bool check(long long int m) {
  int x = 0;
  for (int i = 0; i < n; i++) {
    long long int tem = m;
    if (track[x] <= head[i] && head[i] - track[x] <= tem) {
      long long int piche = head[i] - track[x];
      tem -= piche;
      tem = max(tem / 2, tem - piche);
      while (track[x] <= head[i] + tem) {
        x++;
        if (x == mm) return true;
      }
    } else if (track[x] > head[i]) {
      while (track[x] <= head[i] + m) {
        x++;
        if (x == mm) return true;
      }
    }
  }
  return false;
}
int main() {
  scanf("%d %d", &n, &mm);
  for (int i = 0; i < n; i++) scanf("%I64d", &head[i]);
  for (int i = 0; i < mm; i++) {
    long long int x;
    scanf("%I64d", &x);
    track.push_back(x);
  }
  long long int s = 0ll;
  long long int e = 20000000005ll;
  long long int ans = e;
  while (s <= e) {
    long long int m = (s + e) / 2ll;
    if (check(m))
      ans = m, e = m - 1ll;
    else
      s = m + 1ll;
  }
  printf("%I64d\n", ans);
  ;
  return 0;
}
