#include <bits/stdc++.h>
using namespace std;
int n, m;
long long int h[100010], p[100010];
bool yes(long long int t) {
  long long int start = p[0], cur = h[0];
  for (int i = 0; i < n; i++) {
    if (abs(h[i] - start) > t) continue;
    if (h[i] <= start) {
      cur = h[i] + t;
      if (cur >= p[m - 1]) return true;
      int num = lower_bound(p, p + m, cur) - p;
      if (cur == p[num]) {
        start = start >= p[num + 1] ? start : p[num + 1];
      } else {
        start = p[num];
      }
    } else {
      long long int a = 2 * start + t - h[i];
      long long int b = (h[i] + start + t) / 2;
      cur = a >= b ? a : b;
      if (cur >= p[m - 1]) return true;
      int num = lower_bound(p, p + m, cur) - p;
      if (cur == p[num]) {
        start = start >= p[num + 1] ? start : p[num + 1];
      } else {
        start = p[num];
      }
    }
  }
  return false;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%I64d", &h[i]);
  for (int i = 0; i < m; i++) scanf("%I64d", &p[i]);
  long long int l = 0, r = abs(h[0] - p[0]) + p[m - 1] - p[0];
  long long int mid;
  while (l <= r) {
    mid = (l + r) / 2;
    if (yes(mid)) {
      r = mid - 1;
      if (!yes(mid - 1)) {
        break;
      }
    } else
      l = mid + 1;
  }
  printf("%I64d", mid);
  return 0;
}
