#include <bits/stdc++.h>
using namespace std;
inline void in(long long int &n) {
  n = 0;
  int ch = getchar();
  int sign = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') sign = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
  }
  n = n * sign;
}
long long int a[100005], b[100005];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    in(a[i]);
  }
  for (int i = 1; i <= m; i++) {
    in(b[i]);
  }
  long long int low, high, mid;
  low = 0;
  high = 100000000000;
  while (low < high) {
    mid = low + (high - low) / 2;
    int x, y;
    x = 1;
    y = 1;
    while (x <= n) {
      while (y <= m) {
        if (abs(b[y] - a[x]) > mid) {
          break;
        }
        if (b[y] < a[x]) {
          int p1, p2;
          p1 = p2 = -1;
          for (int i = y + 1; i <= m; i++) {
            if (b[i] <= a[x]) {
              p1 = i;
              continue;
            }
            if (abs(b[y] - a[x]) + abs(b[y] - b[i]) <= mid) {
              p1 = i;
            } else {
              break;
            }
          }
          for (int i = y + 1; i <= m; i++) {
            if (b[i] <= a[x]) {
              p2 = i;
              continue;
            }
            if (abs(b[i] - a[x]) + abs(b[i] - b[y]) <= mid) {
              p2 = i;
            } else {
              break;
            }
          }
          if (p2 > p1) {
            p1 = p2;
          }
          if (p1 == -1) {
            y++;
            break;
          } else {
            y = p1 + 1;
            break;
          }
        } else {
          int p1 = -1;
          for (int i = y + 1; i <= m; i++) {
            if (abs(b[i] - a[x]) <= mid) {
              p1 = i;
            } else {
              break;
            }
          }
          if (p1 == -1) {
            y++;
            break;
          } else {
            y = p1 + 1;
            break;
          }
        }
      }
      x++;
    }
    if (y > m) {
      high = mid;
    } else {
      low = mid + 1;
    }
  }
  printf("%I64d\n", low);
}
