#include <bits/stdc++.h>
using namespace std;
const long long MX = 10000000000LL;
int h, p;
long long heads1[100005], pointer1[100005], heads[100005], pointer[100005];
bool yes(long long t) {
  int i = 0, j = 0;
  for (int i = 0; i < h; ++i) heads[i] = heads1[i];
  for (int i = 0; i < p; ++i) pointer[i] = pointer1[i];
  while (i < h && j < p) {
    if (pointer[j] >= heads[i]) {
      heads[i] += t;
      while (j < p) {
        if (pointer[j] > heads[i]) break;
        ++j;
      }
    } else {
      long long acthead = heads[i];
      long long dist1 = heads[i] - pointer[j];
      if (dist1 > t) return 0;
      long long dist2 = t - 2 * dist1, dist3 = (t - dist1) / 2;
      for (; j < p; ++j) {
        if (pointer[j] > heads[i]) break;
      }
      heads[i] += dist2;
      int k = j, k1 = j;
      for (; k < p; ++k) {
        if (pointer[k] > heads[i]) break;
      }
      heads[i] = acthead;
      heads[i] += dist3;
      for (; k1 < p; ++k1) {
        if (pointer[k1] > heads[i]) break;
      }
      if (k1 > k) {
        j = k1;
      } else
        j = k;
    }
    ++i;
  }
  if (j == p) return 1;
  return 0;
}
int main() {
  cin >> h >> p;
  for (int i = 0; i < h; ++i) {
    cin >> heads1[i];
  }
  for (int i = 0; i < p; ++i) {
    cin >> pointer1[i];
  }
  long long lo = 0, hi = 3LL * MX, mid;
  while (lo <= hi) {
    mid = lo + (hi - lo) / 2;
    bool b1 = yes(mid);
    if (b1 && (mid == lo || !yes(mid - 1))) {
      cout << mid << "\n";
      return 0;
    } else if (b1) {
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << mid << "\n";
  return 0;
}
