#include <bits/stdc++.h>
using namespace std;
bool if_possible(long long* head, long long* data, int n, int m, long long mx) {
  int i = 0, j = m - 1, imx, jmn;
  long long t1, t2, tmx = mx;
  if (n == 1) {
    t1 = data[m - 1] - data[0];
    if (head[0] <= data[0]) {
      t1 += data[0] - head[0];
    } else if (head[0] >= data[m - 1]) {
      t1 += head[0] - data[m - 1];
    } else {
      t1 += min(head[0] - data[0], data[m - 1] - head[0]);
    }
    if (t1 <= mx) return true;
    return false;
  }
  if (data[0] <= head[0]) {
    if ((head[0] - data[0]) > mx) return false;
    tmx -= (head[0] - data[0]);
    while (data[i] <= head[0]) {
      i++;
      if (i == m) break;
    }
    for (; i < m; i++) {
      if ((data[i] - data[0]) > tmx) break;
    }
    imx = i;
    i = 0;
    tmx = mx - (head[0] - data[0]);
    while (data[i] <= head[0]) {
      i++;
      if (i == m) break;
    }
    for (; i < m; i++) {
      if ((2 * (data[i] - head[0])) > tmx) break;
    }
    i = max(i, imx);
  } else {
    for (i = 0; i < m; i++) {
      if ((data[i] - head[0]) > mx) break;
    }
  }
  if (i == m) return true;
  if (data[m - 1] >= head[n - 1]) {
    if ((data[m - 1] - head[n - 1]) > mx) return false;
    tmx = mx - (data[m - 1] - head[n - 1]);
    while ((data[j]) >= head[n - 1]) {
      j--;
      if (j == -1) break;
    }
    for (; j >= 0; j--) {
      if ((data[m - 1] - data[j]) > tmx) break;
    }
    jmn = j;
    tmx = mx - (data[m - 1] - head[n - 1]);
    while ((data[j]) >= head[n - 1]) {
      j--;
      if (j == -1) break;
    }
    for (; j >= 0; j--) {
      if ((2 * (head[n - 1] - data[j])) > tmx) break;
    }
    j = min(j, jmn);
  } else {
    for (j = m - 1; j >= 0; j--) {
      if ((head[n - 1] - data[j]) > mx) break;
    }
  }
  if (j == -1) return true;
  if (j < i) return true;
  if (n == 2) return false;
  return if_possible(head + 1, data + i, n - 2, j - i + 1, mx);
}
long long b_search(long long* head, long long* data, int n, int m, long long l,
                   long long r) {
  if (l == r) {
    if (if_possible(head, data, n, m, l)) return l;
    return -1;
  }
  if (l == (r - 1)) {
    if (if_possible(head, data, n, m, l)) return l;
    if (if_possible(head, data, n, m, r)) return r;
    return -1;
  }
  long long mid = (l + r) / 2, rval;
  if (if_possible(head, data, n, m, mid)) {
    rval = b_search(head, data, n, m, l, mid - 1);
    if (rval == -1) return mid;
    return rval;
  } else {
    return b_search(head, data, n, m, mid + 1, r);
  }
}
int main() {
  int n, m, i, j;
  long long head[100000], data[100000], l, r;
  scanf("%d %d", &n, &m);
  for (i = 0; i < n; i++) {
    scanf("%I64d", &head[i]);
  }
  for (i = 0; i < m; i++) {
    scanf("%I64d", &data[i]);
  }
  l = 0;
  r = data[m - 1] * 2ll;
  r = max(r, head[n - 1] * 2ll);
  printf("%I64d\n", b_search(head, data, n, m, l, r));
  return 0;
}
