Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import numpy as np
n,m=map(int,input().split())
A=np.ones(n)
for i in range(m):
    L,R=map(int,input().split())
    A[:L-1]=0
    A[R:]=0
print(int(sum(A)))

### FIXED CODE ###

import numpy as np
n,m=map(int,input().split())
X=1
Y=n
for i in range(m):
    L,R=map(int,input().split())
    X=max(X,L)
    Y=min(Y,R)
print(max(0,Y-X+1))
### BUGGY CODE ###

n = int(input())
A = list(map(int,input().split()))
ans = 1
 
for i in range(n):
    ans = ans*A[i]
    if 0 in A:
        ans = 0
        break
    elif ans > 10**18:
        ans = -1
        break
 
print(ans)

### FIXED CODE ###

n = int(input())
A = list(map(int,input().split()))
ans = 1

if 0 in A:
  ans = 0
else:
  for i in range(n):
    ans = ans*A[i]
    if ans > 10**18:
        ans = -1
        break
 
print(ans)
### BUGGY CODE ###

n = int(input())
left = 0
right = n - 1

for _ in range(7):
    mid = (left + right) // 2
    print(left)
    sl = input()
    if sl[0] == "V":
        quit()
    print(right)
    sr = input()
    if sr[0] == "V":
        quit()
    print(mid)
    sm = input()
    if sm[0] == "V":
        quit()

    if sm - sl + 1 % 2 == 1 and sm != sl:
        # sl += 1
        sr = sm
        continue
    elif sr - sm + 1 % 2 == 1 and sm != sr:
        # sr -= 1
        sl = sm
        continue
    elif sr - sm + 1 % 2 == 1 and sm == sl:
        sr = sm
        continue
    else:
        sl = sm



### FIXED CODE ###

n = int(input())

left = 0
right = n
print(left, flush=True)
sl = input()
if sl[0] == "V":
    quit()
while right - left > 1:
    mid = (left + right) // 2
    print(mid, flush=True)
    sm = input()
    if sm[0] == "V":
        quit()

    if ((mid - left) % 2 == 1) ^ (sl == sm):
        left = mid
        sl = sm
    else:
        right = mid
### BUGGY CODE ###

N = int(input())
L = []
res = []

for i in range(N):
    S = input()
    L.append(S)
    L.sort()

max_cnt = 0
cnt = 0

L.append(0)

for i in range(len(L) - 1):
    if L[i] == L[i+1]:
        cnt += 1
    else:
        if cnt > max_cnt:
            max_cnt = cnt
            res = []
            res.append(L[i])
        elif cnt == max_cnt:
            res.append(L[i])
        cnt = 0

for i in res:
    print(i)

### FIXED CODE ###

N = int(input())
L = []
res = []

for i in range(N):
    S = input()
    L.append(S)

L.sort()

max_cnt = 0
cnt = 0

L.append(0)

for i in range(len(L) - 1):
    if L[i] == L[i+1]:
        cnt += 1
    else:
        if cnt > max_cnt:
            max_cnt = cnt
            res = []
            res.append(L[i])
        elif cnt == max_cnt:
            res.append(L[i])
        cnt = 0

for i in res:
    print(i)
### BUGGY CODE ###

from itertools import combinations as comb
n = int(input())
l = list(map(int,input().split()))
l.sort()
tri = set()
for a,b,c in comb(l,3):
  if a<b+c and b<c+a and c<a+b:
    tri.add((a,b,c))
print(len(tri))

### FIXED CODE ###

import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
c = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    c += bisect.bisect_right(l,l[j]+l[i]-1) - bisect.bisect_left(l,l[j],j+1)
print(c)
### BUGGY CODE ###

N=int(input())
A=list(map(int, input().split()))

i=1
for j in range(N):
  print(A.count(i))
  i+=1


### FIXED CODE ###

import collections

N=int(input())
A=list(map(int, input().split()))

c = collections.Counter(A)

i=1

for j in range(N):
  print(c[i])
  i+=1
### BUGGY CODE ###

#!/usr/bin/env python3
#ABC75 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,k = LI()
xy = [LI() for _ in range(n)]
ans = inf
for u in range(n):
    for d in range(n):
        for r in range(n):
            for l in range(n):
                cnt = 0
                if xy[u][1] < xy[d][1] or xy[r][0] < xy[l][0]:
                    continue
                for i in range(n):
                    x,y = xy[i]
                    if xy[l][0] <= x <= xy[r][0]  and xy[d][1] <= y <= xy[u][1]:
                        cnt += 1
                if cnt >= k:
                    S = (xy[u][1] - xy[d][1])*(xy[r][0] - xy[l][0])
                    ans = min(ans,S)
print(ans)


### FIXED CODE ###

#!/usr/bin/env python3
#ABC75 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,K = LI()
xy = []
X = []
Y = []
for _ in range(n):
    x,y = LI()
    xy.append([x,y])
    X.append(x)
    Y.append(y)
X.sort(reverse = True)
Y.sort(reverse = True)
ans = inf
for i in range(n):
    uy = Y[i]
    for j in range(i+1,n):
        dy = Y[j]
        for k in range(n):
            rx = X[k]
            for l in range(k+1,n):
                lx = X[l]
                cnt = 0
                for x,y in xy:
                    if lx <= x <= rx and dy <= y <= uy:
                        cnt += 1
                if cnt >= K:
                    S = (uy - dy)*(rx - lx)
                    ans = min(ans,S)
print(ans)
### BUGGY CODE ###

import sys
from collections import deque
input = sys.stdin.readline


def main():
    N, Q = map(int, input().split())
    ans = deque([0] * N)
    con = deque([[] for _ in range(N)])

    for _ in range(N - 1):
        p, c = map(int, input().split())
        con[p-1].append(c-1)
        con[c-1].append(p-1)

    for _ in range(Q):
        p, v = map(int, input().split())
        ans[p-1] += v

    stacks = deque()
    stacks.append((0, -1))

    while stacks:
        stack = stacks.pop()
        node, parent = stack[0], stack[1]

        children = con[node]
        if children:
            for child in children:
                if child == parent:
                    continue
                ans[child] += ans[node]
                stacks.append((child, node))

    print(*ans, sep=' ')


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import deque

N, Q = map(int, input().split())
edge = [[] for i in range(N)]
ops = []
ans = [0] * N

for _ in range(N - 1):
    a, b = map(int, input().split())
    edge[a - 1].append(b - 1)
    edge[b - 1].append(a - 1)
for _ in range(Q):
    ops.append(tuple(map(int, input().split())))

for op in ops:
    node = op[0] - 1
    pnt = op[1]
    ans[node] += pnt

stack = deque()
stack.append((0, -1))

while stack:
    st = stack.pop()
    node, parent = st[0], st[1]
    children = edge[node]
    for child in children:
        if child == parent:
            continue
        ans[child] += ans[node]
        stack.append((child, node))

print(*ans)
### BUGGY CODE ###

# http://tsutaj.hatenablog.com/entry/2017/03/29/204841
class SegmentTree:
    def __init__(self, v, func, init_val):
        self.func = func
        self.init_val = init_val

        sz = len(v)

        self.n = 1
        while self.n < sz:
            self.n *= 2

        self.node = [self.init_val for _ in range(2 * self.n - 1)]
        # 元配列 v をセグメント木で表現する
        # 最下段のノード数は元配列のサイズ以上になる最小の 2 冪 -> これを n とおく
        # セグメント木全体で必要なノード数は 2n - 1 個である

        for i in range(sz):
            self.node[i + self.n - 1] = v[i]
        # 最下段に値を入れたあとに、下の段から順番に値を入れる

        for i in range(self.n - 2, -1, -1):
            self.node[i] = self.func(self.node[2 * i + 1], self.node[2 * i + 2])
        # 値を入れるには、自分の子の 2 値を参照すれば良い

    def update(self, x, val):
        x += self.n - 1
        # 最下段のノードにアクセスする

        self.node[x] = val
        while x > 0:
            x = (x - 1) // 2
            self.node[x] = self.func(self.node[2 * x + 1], self.node[2 * x + 2])
        # 最下段のノードを更新したら、あとは親に上って更新していく

    # 要求区間 [a, b) 中の要素の最小値を答える
    # k := 自分がいるノードのインデックス
    # 対象区間は [l, r) にあたる

    def get_val(self, a, b, k=0, l=0, r=-1):
        if r < 0: r = self.n
        # 最初に呼び出されたときの対象区間は [0, self.n)

        if r <= a or b <= l: return self.init_val
        # 要求区間と対象区間が交わらない -> 適当に返す

        if a <= l and r <= b: return self.node[k]
        # 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う

        vl = self.get_val(a, b, 2 * k + 1, l, (l + r) // 2)
        vr = self.get_val(a, b, 2 * k + 2, (l + r) // 2, r)
        return self.func(vl, vr)
        # 要求区間が対象区間の一部を被覆 -> 子について探索を行う
        # 左側の子を vl ・ 右側の子を vr としている
        # 新しい対象区間は、現在の対象区間を半分に割ったもの


def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)


N = int(input())
a = tuple(map(int, input().split()))

st = SegmentTree(v=a, func=gcd, init_val=0)

g = max(gcd(st.get_val(0, drop_idx), st.get_val(drop_idx + 1, N)) for drop_idx in range(N))
print(g)


### FIXED CODE ###

def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)


N = int(input())
a = list(map(int, input().split()))
a.sort()

g_left = []
g_right = []

t = a[0]
for i in range(N):
    t = gcd(t, a[i])
    g_left.append(t)

t = a[-1]
for i in range(N - 1, -1, -1):
    t = gcd(t, a[i])
    g_right.append(t)

g_right.reverse()

g = 1
for i in range(1, N - 1):
    g = max(g, gcd(g_left[i - 1], g_right[i + 1]))
g = max(g, g_left[N - 2])
g = max(g, g_right[1])

print(g)
### BUGGY CODE ###

n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
t=0
for i in range(n):
  a,b=ab.pop(0)
  if t+a <= b:
    t += a
  else:
    print('No')
    break
else:
  print('Yes')

### FIXED CODE ###

n=int(input())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
t=0
for x in ab:
  if t+x[0] <= x[1]:
    t += x[0]
  else:
    print('No')
    break
else:
  print('Yes')
### BUGGY CODE ###

N=int(input())
A=list(input().split())
cnt=[]

for i in range(N+1):
    if i==0:
        continue
    i=str(i)
    k=A.count(i)
    print(k)

### FIXED CODE ###

N=int(input())
A=list(map(int, input().split()))
cnt=[0]*N

for i in range(N-1):
    cnt[A[i]-1]+=1

for k in range(N):
    print(cnt[k])
### BUGGY CODE ###

import bisect

N,D,A = map(int,input().split())
data = []
for i in range(N):
    X,H = map(int,input().split())
    if H % A == 0:
        data.append([X,H//A])
    else:
        data.append([X,H//A + 1])

data.sort()

X = []
H = []
for i in range(N):
    X.append(data[i][0])
    H.append(data[i][1])

count = 0
for i in range(N):
    if H[i] <= 0:
        continue
    count += H[i]
    p = bisect.bisect_left(X,X[i]+2*D+1)
    for j in range(i+1,min(p,N)):
        H[j] -= H[i]

print(count)

### FIXED CODE ###

from bisect import bisect_right

N, D, A = map(int, input().split())
xh = sorted([list(map(int, input().split())) for _ in range(N)])
ds = [0]*(N+2)
b = 0
for i, (x, h) in enumerate(xh, 1):
  ds[i] += ds[i-1]###(*)
  ###これまでのやつに与えたダメージは引き継がれるものとする
  d = ds[i]
  if d>=h:
    continue###すでに体力以上のダメージを与えた敵
  h -= d###ダメージを与える
  times = h//A if h%A==0 else h//A+1
  ds[i] += times*A
  ds[bisect_right(xh, [x+2*D, float('inf')])+1] -= times*A
  ###(*)のせいで, 2Dよりも向こう側にも、今考えたダメージの影響が
  ###出てしまうので. それを打ち消すために与えるダメージを引いておく
  b += times
print(b)
### BUGGY CODE ###

n = int(input())
a = [int(x) for x in input().split()]

for i in range(n):
    print(a.index(i + 1) + 1,end=' ')
print('\n')

### FIXED CODE ###

n = int(input())
a = [int(x) for x in input().split()]

ans_list = [0 for i in range(n)]
for i in range(n):
    ans_list[a[i] - 1] = i + 1

for i in range(n):
    print(ans_list[i], end=' ')
print('\n')
### BUGGY CODE ###

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n,m=map(int,input().split())
a = [-1]+[int(input()) for _ in range(m)]+[n+1]

def comb(dann):
    num_comb = 0
    for i in range((dann//2)+1):
        num_comb += combinations_count(dann-i, i)
    return num_comb

danns = [(a[i+1] - a[i]) - 2 for i in range(len(a)-1)]

ans = 1
for j in danns:
    ans *= comb(j)
print(ans%1000000007)

### FIXED CODE ###

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]
inf = float("inf")
dp = [0] * (N+1)
for i in A:
	dp[i] = inf
dp[0] = 1
if dp[1] != inf:
	dp[1] = 1
for i in range(2,N+1):
	if dp[i] == inf:
		continue

	a = dp[i-2] if dp[i-2] != inf else 0
	b = dp[i-1] if dp[i-1] != inf else 0

	dp[i] = (a + b) % 1000000007


print(dp[N])
### BUGGY CODE ###

from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  k= int(readline())
  if k<10:
    print(k)
    sys.exit()
  dp = np.ones((10,10), dtype='int64')
  #dp[i-1][j]は、i桁のときの末尾がjの数
  dp[0, 0] = 0
  for i in range(9):
    for j in range(10):
      if j == 0:
        dp[i+1,0] = dp[i,0] + dp[i,1]
      elif j == 9:
        dp[i+1,j] = dp[i,8] + dp[i,9]
      else:
        dp[i+1,j] = dp[i,j-1] + dp[i,j] + dp[i,j+1]
  total = [0]
  #i桁のときの数の累積和
  for i in range(10):
    tmp = total[-1] + dp[i,:].sum()
    total.append(tmp)
  keta = 0
  for i in range(11):
    if total[i]<=k:
      keta = i+1
  #kはketa桁である
  c = 10**(keta-1)
  count = total[keta-1]
  for i in range(c,c*10):
    s = str(i)
    bl = True
    for j in range(keta-1):
      if abs(int(s[j])-int(s[j+1]))>1:
        bl=False
    if bl:
      count +=1
    if count == k:
      print(i)
      sys.exit()
  
if __name__ == '__main__':
  main()

### FIXED CODE ###

from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  k= int(readline())
  l = [1,2,3,4,5,6,7,8,9]
  q = deque(l)
  x = 0
  for _ in range(k):
    x = q.popleft()
    sue = x%10
    if sue != 0:
      q.append(10*x+sue-1)
    q.append(10*x+sue)
    if sue!=9:
      q.append(10*x+sue+1)
  print(x)
if __name__ == '__main__':
  main()
### BUGGY CODE ###

n, q = list(map(int, input().split()))
s = input()
lr = []
for _ in range(q):
    lr.append(list(map(int, input().split())))
for i in range(q):
    print(s[lr[i][0]-1:lr[i][1]].count("AC"))

### FIXED CODE ###

n, q = list(map(int, input().split()))
s = input()
dp = [0, 0]
for i in range(1, n):
    if s[i-1]=="A" and s[i]=="C":
        dp.append(dp[-1]+1)
    else:
        dp.append(dp[-1])
for i in range(q):
    l, r = map(int, input().split())
    ans = dp[r] - dp[l]
    print(ans)
### BUGGY CODE ###

X = int(input())
prime = [2]
for i in range(3, 100004):
  for p in prime:
    is_prime = True
    if i % p == 0:
      is_prime = False
      break
  if is_prime: prime.append(i)

print(min([i for i in prime if i >= X]))

### FIXED CODE ###

X = int(input())
ans = 0
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

for i in range(X, 100004, 1):
  if is_prime(i):
    ans = i
    break

print(ans)
### BUGGY CODE ###

N,K = map(int,input().split())
b = K
r = N-K
mod = 10**9+7
# rのしきりr+1にi個いれる→(r+1)Ci
# bはしきりb-1にi-1個入れる→(b-1)C(i-1)

for i in range(1,K+1):
    ans = 1
    for j in range(1,i+1):
        ans *= (r+1)-(j-1)
        ans *= pow(j,mod-2,mod)
        ans %= mod
    for k in range(1,i):
        ans *= (b-1)-(k-1)
        ans *= pow(k,mod-2,mod)
        ans %= mod
    print(ans)

### FIXED CODE ###

N,K = map(int,input().split())
b = K
r = N-K
mod = 10**9+7
# rのしきりr+1にi個いれる→(r+1)Ci
# bはしきりb-1にi-1個入れる→(b-1)C(i-1)

ans = (r+1)
print(ans)
for i in range(2,K+1):
    ans *= (r+1)-(i-1)
    ans *= (b-1)-(i-2)
    ans *= pow(i,mod-2,mod)
    ans *= pow(i-1,mod-2,mod)
    ans %= mod
    print(ans)
### BUGGY CODE ###

S = input()
Q = int(input())
revcount = 0

ans = []
ans.append(S)
T = [0,0,""]
for i in range(Q):
  TS = input()
  if TS == "1":
    revcount += 1
  else:
    T = TS.rstrip().split(" ")
    if (int(T[1]) == 1 and revcount % 2 == 0) or (int(T[1]) == 2 and revcount % 2 == 1):
      ans.append(T[2] + ans[0])
      ans.pop(0)
    else:
      ans.append(ans[0] + T[2])
      ans.pop(0)
if revcount % 2 == 1:
  print(ans[0][::-1])
else:
  print(ans[0])
  

### FIXED CODE ###

S = list(input())
mae = []
ato = []
rev = False
Q = int(input())
for i in range(Q):
    A = list(input().rstrip().split(" "))
    if int(A[0]) == 1:
        if rev:
            rev = False
        else:
            rev = True
    else:
        if (rev and int(A[1]) == 2 or not rev and int(A[1]) == 1):
            mae.append(A[2])
        else:
            ato.append(A[2])
if rev:
    ato.reverse()
    S.reverse()
    print("".join(ato) + "".join(S) + "".join(mae))
else:
    mae.reverse()
    print("".join(mae) + "".join(S) + "".join(ato))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ab = [abs(a[0]) if i==0 else abs(a[-1]) if i==n else abs(a[i]-a[i-1]) for i in range(n+1)]

for i in range(n):
    if i==0:
        print(sum(ab) - abs(a[i]-a[i+1])-abs(a[i])+abs(a[i+1]))
    elif i==n-1:
        print(sum(ab) - abs(a[i-1]-a[i])-abs(a[i])+abs(a[i-1]))
    else:
        print(sum(ab) - abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]))

### FIXED CODE ###

def main():
    n = int(input())
    a = list(map(int, input().split()))
    ab = abs(a[0])+abs(a[-1])
    for i in range(n-1):
        ab += abs(a[i]-a[i+1])

    for i in range(n):
        if i==0:
            print(ab - abs(a[i]-a[i+1])-abs(a[i])+abs(a[i+1]))
        elif i==n-1:
            print(ab - abs(a[i-1]-a[i])-abs(a[i])+abs(a[i-1]))
        else:
            print(ab - abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]))

if __name__ == "__main__":
    main()
### BUGGY CODE ###

K,S=map(int,input().split())
if 2<=K<=2500 and 0<=S<=3*K:
    Ks=[]
    wa=[]
    for i in range(K+1):
        Ks.append(i)
    X,Y,Z =Ks,Ks,Ks
    for x in X:
        if x<=S:
            X_=[]
            X_.append(x)
            for y in Y:
                if y<=S:
                    X_Y_=[]
                    X_Y_=X_.copy()
                    X_Y_.append(y)
                    for z in Z:
                        if z<=S:
                            X_Y_Z_=X_Y_.copy()
                            X_Y_Z_.append(z) 
                            wa_=sum(X_Y_Z_)
                            wa.append(wa_)
    print(len([c for c in wa if c==S]))

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
count=0
for x in range(K+1):
    for y in range(K+1):
        if S-(x+y)>=0 and S-(x+y)<=K: count+=1
print(count)
### BUGGY CODE ###

def ai():return input()#s
def a():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y
k= []
l = []
f = 0
def say(i):return print("Yes" if i == 0 else "No")
def Say(i):return print("YES" if i == 0 else "NO")

a = int(input())
c =[0]*a
for i in range(a):
    t = int(input())
    k.append(t)
p = set(k)
for i in p:
    f+=k.count(i)%2
print(f)

### FIXED CODE ###

def ai():return input()#s
def a():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y
k= []
l = []
f = 0
def say(i):return print("Yes" if i == 0 else "No")
def Say(i):return print("YES" if i == 0 else "NO")

a = int(input())
c=set()
for i in range(a):
    t = int(input())
    if t in c:
        c.remove(t)
    else:
        c.add(t)
print(len(c))
### BUGGY CODE ###

#coding:utf-8
import numpy as np
n,k = map(int,input().split())
ls = list(map(int,input().split()))

# n, k = 5, 3
# ls = [-30,-10,10,20,50]
#
# n,k = 3,2
# ls=[10,20,30]

# n,k = 1,1
# ls = [0]

# n,k=8,5
# ls=[-9,-7,-4,-3,1,2,3,4]

def set_max(ls):
    try:
        return set([max(ls)])
    except:
        return set()
def set_min(ls):
    try:
        return set([min(ls)])
    except:
        return set()


plus = list(filter(lambda n:n>=0, ls))
minus = list(filter(lambda n:n<=0, ls))

neighbor = set_max(minus) | set_min(plus)

#print (neighbor)
answer = []
for i in range(n-k+1):
    if len(set(ls[i:i+k])&neighbor)>0:
        #print (ls[i:i+k])
        #print (np.sign(ls[i]*ls[i+k-1]))
        temp = [abs(ls[i]),abs(ls[i+k-1])]
        if np.sign(ls[i]*ls[i+k-1])<0:

            answer.append(2*min(temp)+max(temp))
        else:
            answer.append(max(temp))
print (min(answer))

# first = -1
# for i,point in enumerate(ls):
#     if point >= 0:
#         first = i
#         break
# size=k+1
# ans = []
# for i in range(size):
#     if first-size+i+1>=0 and first+i-1< len(ls):
#         temp = [0,ls[first-size+i+1],ls[first+i-1]]
#         temp = [abs(min(temp)),abs(max(temp))]
#         ans.append((2*min(temp)+max(temp)))
# print (min(ans))


### FIXED CODE ###

#coding:utf-8
import numpy as np
n,k = map(int,input().split())
ls = list(map(int,input().split()))

# n, k = 5, 3
# ls = [-30,-10,10,20,50]
#
# n,k = 3,2
# ls=[10,20,30]

# n,k = 1,1
# ls = [0]

# n,k=8,5
# ls=[-9,-7,-4,-3,1,2,3,4]
if not (0 in ls):
    ls.append(0)
    k+=1
#print (ls)

ls = np.array(ls)
ls.sort()
#print (ls)

idx = np.where(ls==0)[0][0]
#print (idx,k)
#print (idx+k)
start = max(0,idx-k)
goal = min(idx+k,len(ls)-1)

#print (start,goal)
answer = []
for i in range(goal-(k-1)+1):
    #print (i,i+k-1)
    mi = min(abs(ls[i]),abs(ls[i+k-1]))
    ma = max(abs(ls[i]),abs(ls[i+k-1]))
    #print (mi,ma)
    answer.append(2*mi+ma)
print (min(answer))
# def set_max(ls):
#     if len(ls)>0:
#         return set([max(ls)])
#     else:
#         return set()
# def set_min(ls):
#     if len(ls)>0:
#         return set([min(ls)])
#     else:
#         return set()
#
#
# plus = list(filter(lambda n:n>=0, ls))
# minus = list(filter(lambda n:n<=0, ls))
#
# neighbor = set_max(minus) | set_min(plus)
#
# #print (neighbor)
# answer = []
# cnt = 0
# for i in range(n-k+1):
#     if len(set(ls[i:i+k])&neighbor)>0:
#
#         #print (ls[i:i+k])
#         #print (np.sign(ls[i]*ls[i+k-1]))
#         temp = [abs(ls[i]),abs(ls[i+k-1])]
#         if np.sign(ls[i]*ls[i+k-1])<0:
#
#             answer.append(2*min(temp)+max(temp))
#         else:
#             answer.append(max(temp))
#         cnt += 1
#         if cnt == k + 1:
#             break
# print (min(answer))

# first = -1
# for i,point in enumerate(ls):
#     if point >= 0:
#         first = i
#         break
# size=k+1
# ans = []
# for i in range(size):
#     if first-size+i+1>=0 and first+i-1< len(ls):
#         temp = [0,ls[first-size+i+1],ls[first+i-1]]
#         temp = [abs(min(temp)),abs(max(temp))]
#         ans.append((2*min(temp)+max(temp)))
# print (min(ans))