#include <bits/stdc++.h>
using namespace std;
long long int d[100005], pos[100005];
bool vis[100005];
int n, m;
bool check(long long int x) {
  memset(vis, 0, sizeof(vis));
  int i, l, r;
  l = r = 1;
  long long int t;
  for (i = 1; i <= n; i++) {
    while (r <= m) {
      if (d[l] <= pos[i] && d[r] <= pos[i]) {
        t = abs(pos[i] - d[l]);
      } else if (d[l] >= pos[i] && d[r] >= pos[i]) {
        t = abs(pos[i] - d[r]);
      } else {
        t = min(abs(pos[i] - d[l]) * 2 + abs(pos[i] - d[r]),
                abs(pos[i] - d[r]) * 2 + abs(pos[i] - d[l]));
      }
      if (t <= x) {
        vis[r] = 1;
        r++;
      } else {
        l = r;
        break;
      }
    }
  }
  for (i = 1; i <= m; i++) {
    if (vis[i] != 1) {
      return 0;
    }
  }
  return 1;
}
int main() {
  int i;
  long long int l, r, k;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> pos[i];
  for (i = 1; i <= m; i++) cin >> d[i];
  l = 0;
  r = 3e10;
  long long ans = 0;
  while (l <= r) {
    k = (l + r) / 2;
    if (check(k)) {
      ans = k, r = k - 1;
    } else {
      l = k + 1;
    }
  }
  cout << ans << endl;
}
