#include <bits/stdc++.h>
long long h[100005];
long long p[100005];
int n, m;
int find(long long k) {
  int l = -1;
  int r = m;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (p[mid] == k)
      return mid;
    else if (p[mid] > k)
      r = mid;
    else
      l = mid;
  }
  return l;
}
bool judge(long long ans) {
  int last = 0;
  for (int i = 0; i < n; ++i) {
    if (p[last] < h[i]) {
      long long num = ans - (h[i] - p[last]) * 2 + h[i];
      int k = find(num);
      if (ans - (h[i] - p[last]) >= 0) {
        num = (ans - (h[i] - p[last])) / 2 + h[i];
        int k2 = find(num);
        if (k2 > k) k = k2;
      }
      last = k + 1;
    } else {
      long long num = ans + h[i];
      int k = find(num);
      last = k + 1;
    }
    if (last == m) return true;
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%lld", &h[i]);
  for (int i = 0; i < m; ++i) scanf("%lld", &p[i]);
  long long l = -1;
  long long r = 100000;
  r = r * r * 2;
  p[m] = r;
  while (r - l > 1) {
    long long mid = (l + r) / 2;
    if (judge(mid))
      r = mid;
    else
      l = mid;
  }
  printf("%lld\n", r);
}
