#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10, MOD = 1e9 + 7;
long long n, m;
long long h[N], p[N];
void read_input() {
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (long long i = 0; i < m; i++) {
    cin >> p[i];
  }
}
bool check(long long x) {
  long long ind = 0;
  for (long long i = 0; i < n; i++) {
    if (ind == m) {
      break;
    }
    long long dis = 0;
    if (p[ind] < h[i]) {
      dis = h[i] - p[ind];
    }
    long long tmp = max((x - dis) / 2, x - 2 * dis);
    if (x < dis) {
      return 0;
    }
    while (ind < m) {
      if (h[i] + tmp < p[ind]) {
        break;
      }
      ind++;
    }
  }
  if (ind == m) {
    return 1;
  }
  return 0;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  read_input();
  long long l = -1, r = 2e10 + 10;
  while (r - l > 1) {
    long long mid = (l + r) / 2;
    if (check(mid)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r;
  return 0;
}
