#include <bits/stdc++.h>
using namespace std;
long long int a[1000009];
long long int b[1000009];
long long int n, m;
long long int ck(long long int p) {
  if (p < 0) return 0;
  long long int i, j, x, y, t, d;
  x = 0;
  y = 0;
  while (1) {
    if (b[y] <= a[x]) {
      d = abs(b[y] - a[x]);
      if (d > p) return 0;
      t = max((p - d) / 2, p - 2 * d);
      while (b[y] <= a[x] || abs(b[y] - a[x]) <= t) y++;
    } else {
      while (abs(b[y] - a[x]) <= p) y++;
    }
    if (y == m) return 1;
    x++;
    if (x == n) return 0;
  }
}
int main() {
  long long int i, j, k, sum, p, q, z, x, y;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> a[i - 1];
  for (i = 1; i <= m; i++) cin >> b[i - 1];
  long long int r, l;
  b[m] = 1000000000000000;
  l = 0;
  r = 100000000000;
  while (1) {
    p = (l + r) / 2;
    x = ck(p);
    y = ck(p - 1);
    if (x == 0) {
      l = p + 1;
      continue;
    } else if (y == 1) {
      r = p - 1;
      continue;
    } else {
      cout << p;
      exit(0);
    }
  }
}
