{"trustable":false,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"MD","content":"Gugug has invented a new type of hard drive, it has not one, but *n* different heads that can read data in parallel.\n\nWhen viewed from the side, Gugug\u0027s hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. \n\nAt the beginning, the *i*-th reading head is above the track number $h_i$. For each of the reading heads, the hard drive\u0027s firmware can move the head exactly one track to the right or to the left, or leave it on the current track. \n\nDuring the operation each head\u0027s movement does not affect the movement of the other heads: the heads can change their relative order; there can be multiple reading heads above any of the tracks. A track is considered read if at least one head has visited this track. In particular, all of the tracks numbered $h_1, h_2$, ..., $h_n$ have been read at the beginning of the operation.\n\u003ccenter\u003e \n \u003cimg class\u003d\"tex-graphics\" SRC\u003d\"CDN_BASE_URL/993bc9ca28c14384701e9a64b14e30da?v\u003d1564855964\" style\u003d\"max-width: 100.0%;max-height: 100.0%;\"\u003e \n\u003c/center\u003e\nGugug needs to read the data on $m$ distinct tracks with numbers $p_1, p_2, ..., p_m$. Determine the minimum time the hard drive firmware needs to move the heads and read all the given tracks. Note that an arbitrary number of other tracks can also be read.\n"}},{"title":"Input","value":{"format":"MD","content":"The first line of the input contains two space-separated integers *n*, *m* (1 ≤ *n*, *m* ≤ 10^5) — the number of disk heads and the number of tracks to read, accordingly. The second line contains *n* distinct integers $h_i$ in ascending order $(1 ≤ h_i ≤ 10^{10}, h_i \u003c h_{i + 1})$ — the initial positions of the heads. The third line contains *m* distinct integers $p_i$ in ascending order $(1 ≤ p_i ≤ 10^{10}, p_i \u003c p_{i + 1})$ - the numbers of tracks to read.\n\nPlease, do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier."}},{"title":"Output","value":{"format":"MD","content":"Print a single number — the minimum time required, in seconds, to read all the needed tracks.\n"}},{"title":"Examples","value":{"format":"MD","content":"\u003cdiv class\u003d\"sample-test\"\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e3 4\u003cbr\u003e2 5 6\u003cbr\u003e1 3 6 8\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"output\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e\n \u003cpre\u003e2\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e3 3\u003cbr\u003e1 2 3\u003cbr\u003e1 2 3\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"output\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e\n \u003cpre\u003e0\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"input\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Input\n \u003c/div\u003e\n \u003cpre\u003e1 2\u003cbr\u003e165\u003cbr\u003e142 200\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n \u003cdiv class\u003d\"output\"\u003e\n \u003cdiv class\u003d\"title\"\u003e\n Output\n \u003c/div\u003e\n \u003cpre\u003e81\u003cbr\u003e\u003c/pre\u003e\n \u003c/div\u003e\n\u003c/div\u003e"}},{"title":"Note","value":{"format":"MD","content":"\u003cp\u003eThe first test coincides with the figure. In this case the given tracks can be read in 2 seconds in the following way: \u003c/p\u003e\n\u003col\u003e \n \u003cli\u003e during the first second move the 1-st head to the left and let it stay there; \u003c/li\u003e\n \u003cli\u003e move the second head to the left twice; \u003c/li\u003e\n \u003cli\u003e move the third head to the right twice (note that the 6-th track has already been read at the beginning). \u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003eOne cannot read the tracks in 1 second as the 3-rd head is at distance 2 from the 8-th track.\u003c/p\u003e"}}]}