#include <bits/stdc++.h>
using namespace std;
const int maxn = 100050;
long long h[maxn], p[maxn], vis[maxn];
int n, m;
bool check(long long mid) {
  long long dest;
  int pt, j;
  memset(vis, 0, sizeof(vis));
  for (int i = pt = 0; i < n; i++) {
    if (h[i] <= p[pt])
      dest = h[i] + mid;
    else {
      if (mid < (h[i] - p[pt])) break;
      dest =
          max(p[pt] + mid - (h[i] - p[pt]), h[i] + (mid - (h[i] - p[pt])) / 2);
    }
    for (j = pt; p[j] <= dest && j < m; j++) vis[j] = 1;
    if (vis[m - 1]) break;
    pt = j;
  }
  if (vis[m - 1])
    return true;
  else
    return false;
}
int main() {
  long long i, j, cj, len, mid, l, r, dest;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%I64d", &h[i]);
  for (i = 0; i < m; i++) scanf("%I64d", &p[i]);
  if (h[0] < p[0])
    len = p[m - 1] - h[0];
  else {
    len = h[0] - p[0];
    if (h[0] < p[m - 1])
      len = min(len * 2 + p[m - 1] - h[0], len + 2 * (p[m - 1] - h[0]));
  }
  l = 0, r = len;
  int flag;
  while (l < r) {
    mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%I64d\n", l);
  return 0;
}
