#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 7;
const long long oo = 1e18 + 7;
long long h[mx], p[mx], th[mx];
int n, m;
bool valid(long long tm) {
  for (int i = 0; i < n; ++i) {
    th[i] = h[i];
  }
  int i = 0, j = 0;
  long long rem = tm;
  while (j < m) {
    if (i == n) {
      return false;
    }
    if (th[i] <= p[j]) {
      if (rem >= p[j] - th[i]) {
        rem -= p[j] - th[i];
        th[i] = p[j];
        j++;
      } else {
        i++;
        rem = tm;
      }
    } else if (th[i] - p[j] <= rem) {
      long long nj[2] = {j, j}, nrem[2] = {rem, rem};
      while (p[nj[0]] <= th[i]) {
        nj[0]++;
      }
      nj[1] = nj[0];
      nrem[0] -= 2 * (th[i] - p[j]);
      long long pos = th[i];
      while (nj[0] < m && nrem[0] >= p[nj[0]] - pos) {
        nrem[0] -= p[nj[0]] - pos;
        pos = p[nj[0]];
        nj[0]++;
      }
      nrem[1] -= th[i] - p[j];
      pos = th[i];
      while (nj[1] < m && nrem[1] >= 2 * (p[nj[1]] - pos)) {
        nrem[1] -= 2 * (p[nj[1]] - pos);
        pos = p[nj[1]];
        nj[1]++;
      }
      j = max(nj[0], nj[1]);
      i++;
      rem = tm;
    } else {
      return false;
    }
  }
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> p[i];
  }
  long long lo = -1, hi = oo;
  while (hi - lo > 1) {
    long long mid = (lo + hi) / 2;
    if (valid(mid)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  cout << hi << "\n";
  return 0;
}
