#include <bits/stdc++.h>
using namespace std;
vector<long long> head, track;
bool visited[100001];
bool check(long long time) {
  memset(visited, 0, sizeof(visited));
  int br = 0;
  int j = 0;
  for (int i = 0; i < head.size(); i++) {
    long long temp = time;
    long long back = 0;
    if (track[j] < head[i]) {
      if (head[i] - track[j] > time) {
        return 0;
      } else {
        back = head[i] - track[j];
        while (track[j] <= head[i] && j < track.size()) {
          visited[j++] = true;
          br++;
        }
      }
    }
    if (j == track.size()) break;
    temp = max(time - back * 2, (time - back) / 2);
    while (track[j] <= head[i] + temp && j < track.size()) {
      visited[j++] = true;
      br++;
    }
    if (br == track.size()) break;
  }
  if (br == track.size())
    return true;
  else
    return false;
}
int main() {
  long long n, m, a, left = 0, right = 100000000000, mid = 50000;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a;
    head.push_back(a);
  }
  for (int i = 0; i < m; i++) {
    cin >> a;
    track.push_back(a);
  }
  while (left < right) {
    mid = (left + right) / 2;
    if (check(mid)) {
      right = mid;
    } else
      left = mid + 1;
  }
  mid = (left + right) / 2;
  cout << mid << endl;
}
