#include <bits/stdc++.h>
using namespace std;
long long g[100000], o[100000];
long long odl(long long a, long long b) {
  if (a - b > 0) return a - b;
  return b - a;
}
bool ok(long long t, int n, int m) {
  long long od, p, d;
  for (int i = n - 1; i >= 0; i--) {
    if (o[m - 1] - g[i] > t) return 0;
    od = o[m - 1] - g[i];
    if (od < 0) od = 0;
    p = (o[m - 1] >= g[i]);
    while (1) {
      if (m == p) return 1;
      if (o[m - 1 - p] >= g[i]) {
        p++;
        continue;
      }
      if (2 * odl(g[i], o[m - 1 - p]) + od <= t)
        p++;
      else
        break;
    }
    d = (o[m - 1] >= g[i]);
    while (1) {
      if (m == d) return 1;
      if (o[m - 1 - d] >= g[i]) {
        d++;
        continue;
      }
      if (odl(o[m - 1 - d], g[i]) + 2 * od <= t)
        d++;
      else
        break;
    }
    if (p > d)
      m -= p;
    else
      m -= d;
  }
  if (m > 0) return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> g[i];
  for (int i = 0; i < m; i++) cin >> o[i];
  long long p = 0, k = 1000000, s;
  k = k * k;
  while (k - p > 1) {
    s = (p + k) / 2;
    if (ok(s, n, m))
      k = s;
    else
      p = s + 1;
  }
  if (ok(p, n, m))
    cout << p << "\n";
  else
    cout << k << "\n";
}
