#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
long long a[N], b[N];
int n, m;
bool check(long long x) {
  int p = 1;
  for (int i = 1; i <= n; ++i) {
    long long dist = 0;
    long long poz = a[i];
    for (int q = p; q <= m + 1; ++q) {
      if (q == m + 1) {
        p = q;
        break;
      }
      if (b[q] <= a[i]) {
        if (a[i] - b[p] > x) {
          p = q;
          break;
        }
      } else if (b[q] >= a[i] && b[p] >= a[i]) {
        if (b[q] - a[i] > x) {
          p = q;
          break;
        }
      } else if (b[q] >= a[i] && b[p] < a[i]) {
        if (b[q] - b[p] + min(b[q] - a[i], a[i] - b[p]) > x) {
          p = q;
          break;
        }
      }
    }
  }
  return (p > m);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; ++i) {
    cin >> b[i];
  }
  long long st = 0;
  long long dr = 1LL << 40;
  while (st <= dr) {
    long long mij = (st + dr) >> 1;
    if (check(mij)) {
      dr = mij - 1;
    } else {
      st = mij + 1;
    }
  }
  cout << dr + 1;
  return 0;
}
