#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 100010;
long long head[N_MAX], track[N_MAX];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%I64d", head + i);
  for (int i = 0; i < m; i++) scanf("%I64d", track + i);
  long long lb = -1, ub = 2e10 + 10;
  while (ub - lb > 1) {
    long long mid = (ub + lb) / 2;
    int ptr = 0;
    for (int i = 0; i < n && ptr < m; i++) {
      long long nxt;
      if (track[ptr] >= head[i]) {
        nxt = mid;
      } else if (head[i] - track[ptr] > mid) {
        break;
      } else {
        if (mid >= 3 * (head[i] - track[ptr])) {
          nxt = mid - 2 * (head[i] - track[ptr]);
        } else {
          nxt = (mid - (head[i] - track[ptr])) / 2;
        }
      }
      while (ptr < m && track[ptr] <= head[i] + nxt) ptr++;
    }
    (ptr == m) ? ub = mid : lb = mid;
  }
  printf("%I64d\n", ub);
  return 0;
}
