using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;

class yuki325
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static string[] SList(int n) => Enumerable.Repeat(0, n).Select(_ => ReadLine()).ToArray();
    static void Main()
    {
        var c = NList;
        var (n, m) = (c[0], c[1]);
        var a = NList;
        var b = new Queue<int>(NList);

        var res = Math.Max(0, a[0] - b.Peek());
        while (b.Peek() < a[0]) b.Dequeue();

        for (var i = 1; i < a.Length; ++i)
        {
            var list = new List<int>();
            while (b.Count > 0 && b.Peek() < a[i]) list.Add(b.Dequeue());
            if (list.Count == 0) continue;
            if (list.Count == 1)
            {
                res += Math.Min(list[0] - a[i - 1], a[i] - list[0]);
                continue;
            }
            list.Insert(0, a[i - 1]);
            list.Add(a[i]);
            var sub = 0;
            for (var d = 0; d < list.Count - 1; ++d)
            {
                sub = Math.Max(sub, list[d + 1] - list[d]);
            }
            res += a[i] - a[i - 1] - sub;
        }

        if (b.Count > 0) res += Math.Max(0, b.Last() - a.Last());
        WriteLine(res);
    }
    static void DebugTable<T>(T[][] table)
    {
        Console.WriteLine("{");
        foreach (var list in table) Console.WriteLine(string.Join(", ", list));
        Console.WriteLine("}");
    }
}