#include <bits/stdc++.h>
using namespace std;
long long leader[110000], p[110000];
long long n, m, i, j, k;
bool can(long long cost) {
  for (i = 0, j = 0; i < n && j < m; ++i) {
    long long summ = cost;
    if (leader[i] == p[j] && j < m) ++j;
    if (j >= m) break;
    summ -= abs(leader[i] - p[j]);
    long long temp = leader[i] - p[j];
    if (summ < 0) continue;
    if (temp > 0) {
      int t = j;
      while (p[j] <= leader[i] && j < m) ++j;
      while (cost >= p[j] - p[t] + min(p[j] - leader[i], leader[i] - p[t]) &&
             j < m)
        ++j;
      if (j >= m) break;
    } else {
      while (p[j] <= leader[i] + cost && j < m) ++j;
      if (j >= m) break;
    }
  }
  if (j >= m)
    return 1;
  else
    return 0;
}
int main() {
  long long cost = 0;
  scanf("%I64d%I64d", &n, &m);
  for (i = 0; i < n; ++i) scanf("%I64d", &leader[i]);
  for (i = 0; i < m; ++i) scanf("%I64d", &p[i]);
  i = 0, j = 0;
  long long l = -1, r = max(p[m - 1] * 2, leader[n - 1] * 2);
  if (n != 1)
    while (r - l > 1) {
      long long mid = l + (r - l) / 2;
      if (can(mid))
        r = mid;
      else
        l = mid;
    }
  if (n != 1)
    printf("%I64d", r);
  else {
    if (leader[0] < p[0])
      printf("%I64d", p[m - 1] - leader[0]);
    else if (leader[0] > p[m - 1])
      printf("%I64d", leader[0] - p[0]);
    else {
      printf("%I64d",
             p[m - 1] - p[0] + min(leader[0] - p[0], p[m - 1] - leader[0]));
    }
  }
  return 0;
}
