peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
# Code for C - Guess The Number
# Use input() to fetch data from STDIN
import sys
[n, m] = [int(x) for x in input().split()]
s = []
c = []

for i in range(m):
    [x, y] = [int(x) for x in input().split()]
    s.append(x)
    c.append(y)

for x in range(1, 1000):
    a = str(x)
    if len(a) != n:
        continue

    test = all([a[i - 1] == str(j) for i, j in zip(s, c)])
    if test:
        print(x)
        sys.exit()

print("-1")
# Judge status: Accepted
n, k = map(int,input().split())
print(min(n%k, abs(n%k-k)))
# Judge status: Wrong Answer
s,w = map(int,input().split())
 
if s >= w:
  print("safe")
else:
  print("unsafe")
# Judge status: Wrong Answer
N = int(input())

line = list(map(int,input().split()))

count = 0
while count <= N:
    for i in range(N):
        try:
            if line[i] == i + 1:
                True
            else:
                line.pop(i)
                break
        except:
            break
    count += 1
    
print(N - len(line))
# Judge status: Wrong Answer
a=[int(i) for i in input().split()]

a.sort()

if a[0]==a[1]+a[2]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n,m=map(int,input().split())
#1とnがつながっているときのa,bの最短距離
def dist(a,b):
  return min(abs(a-b),n-abs(a-b))

a,b = n,1
S=set()
for i in range(m):
  distab = dist(a,b)
  #distabがnの半分のとき
  if 2*distab == n or distab in S:
    a -= 1
  print(a,b)
  S.add(distab)
  a -= 1
  b += 1
# Judge status: Accepted
## C - Multiple Gift
import math
X, Y = map(int, input().split())
count = 0
while X <= Y:
    X *= 2
    count += 1
print(count)
# Judge status: Accepted
A, B = map(int, input().split())
A, B = max(A, B), min(A, B)
print(2 * A if A == B else 2 * A - 1)
# Judge status: Accepted
N = int(input())
d = sorted(list(map(int,input().split())))
Kmin,Kmax = d[N//2-1],d[N//2]
print(Kmax-Kmin)
# Judge status: Accepted
import numpy as np
N, W = map(int, input().split())
dp = np.zeros(W+1, np.int64)
for i in range(N):
    w, v = map(int, input().split())
    dp[w:] = np.maximum(dp[w:], dp[:-w] + v)
print(dp[-1])
# Judge status: Accepted
# -*- coding: utf-8 -*-
n = int(input())
s = list(input())
if s.count("W") == 0:
    print(0)
    exit()
print(s[:s.count('R')].count("W"))
# Judge status: Accepted
print(sum([i for i in range(1, int(input())+1)]))
# Judge status: Wrong Answer
l=list(map(int,input().split()))
l.sort()
k=int(input())
print(l[0]+l[1]+l[2]**k)
# Judge status: Wrong Answer
from collections import Counter
n = int(input())
a = [min(x//400, 8) for x in map(int, input().split())]
a = Counter(a)

if len(a) == 1 and a[8] != 0:
    min_a = 1
    max_a = a[8]
elif a[8] != 0:
    min_a = len(a)-1
    max_a = min([min_a+a[8], 8])
else:
    min_a = max_a = len(a)
print(min_a, max_a)
# Judge status: Wrong Answer
import math

R = int(input())
2*math.pi*R
# Judge status: Accepted
t_hp, t_atk, a_hp, a_atk = map(int, input().split())
while (1):
    a_hp -= t_atk
    if a_hp <= 0:
        ans = "Yes"
        break
    t_hp -= a_atk
    if t_hp <= 0:
        ans = "No"
        break
    
print(ans)
# Judge status: Accepted
n, m = map(int, input().split())
x = [0]*n
y = [0]*n
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a == 0:
        x[b] = 1
    if b == n-1:
        y[a] = 1

f = 0
for i in range(n):
    if x[i]*y[i] > 0:
        f = 1

if f:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
# Judge status: Accepted
O=list(input())
E=list(input())
len_=len(E)
for i in range(len_):
    O.insert(i*2+1,E[i])
print(''.join(O))
# Judge status: Accepted
A, B, C = map(int, input().split())

if C - (A - B) < 0:
    print(0)
else:
    print(C - (A - B))
# Judge status: Accepted
from itertools import*
(n,), *D = [list(map(int, o.split())) for o in open(0)]
dp = [[0]*3 for _ in [None]*-~n]
for i in range(n):
  for j, k in permutations(range(3), 2):
    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + D[i][k])
print(max(dp[n]))
# Judge status: Accepted
import sys

def main():
    input = sys.stdin.readline
    N, K = map(int, input().rstrip().split())
    trees = []

    for _ in range(N):
        trees.append(int(input()))

    trees.sort()
    min_diff = float("inf")

    for i in range(K-1, N):
        min_diff = min(min_diff, trees[i]-trees[i-K+1])
        
    
    print(min_diff)



if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
from collections import Counter

N, K = list(map(int,input().split()))
H = []
for i in range(N):
    H.append(int(input()))
H = sorted(H,reverse = False)
C = Counter(H)
CH = list(C.values()) 

cnt = 0
for i in range(len(CH)):
    if CH[i] >= K:
        cnt += 0
        break
if cnt != 0:
    print('0')
else:
    print(H[K-1] - H[0])
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))

c1 = 0
c2 = 0
c4 = 0
for i in range(n):
    if a[i] % 4 == 0:
        c4 += 1
    elif a[i] % 2 == 0:
        c2 += 1
    elif a[i] == 1:
        c1 += 1
if c2 == n:
    print('Yes')
    quit()

n -= c2
c2 %= 2
n += c2
f = n // 2

if c4 >= f:
    print('Yes')
    quit()
else:
    print('No')
# Judge status: Accepted
a, b, c = input()

if a==b==c:
    print('No')
else:
    print('Yes')
# Judge status: Accepted
a, b, c = map(int, input().split())
if c - a - b <= 0:
    print("No")
    exit()
if 4 * a * b < (c - a - b) * (c - a - b):
    print("Yes")
    exit()
else:
    print("No")
    exit()
# Judge status: Accepted
import sys
input = sys.stdin.readline

N = int(input())
S = input().rstrip('\r\n')
counts = [0] * N
count = 0
for i, s in enumerate(S):
    counts[i] += count
    if s == 'W':
        count += 1
count = 0
for i, s in enumerate(S[::-1]):
    counts[N-1-i] += count
    if s == 'E':
        count += 1
ans = min(counts)
print(ans)
# Judge status: Accepted
import math

a = list(map(int,input().split()))
A = a[0]
B = a[1]
H = a[2]
M = a[3]
x = math.sqrt(A*A + B*B - 2*A*B*math.cos(math.radians(6*M - 30*H -  0.5*M)))
print(x)
# Judge status: Wrong Answer
x,y = map(int,input().split())

a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]

if x in a and y in a:
  print("YES")
elif x in b and y in b:
  print("YES")
elif x in c and y in c:
  print("YES")
else:
  print("NO")
# Judge status: Wrong Answer
N=int(input())
if 2<=N<=3:
    print("2")
elif 4<=N<=7:
    print("4")
elif 8<=N<=15:
    print("8")
elif 16<=N<=31:
    print("16")
elif 32<=N<=63:
    print("32")
elif 64<=N<=100:
    print("64")
elif N==1:
    print("0")
# Judge status: Wrong Answer
x, a, b = map(int, input().split())

if (b - a) < 0:
  print('delicious')
elif (b - a) <= x:
  print('safe')
else:
  print('dangerous')
# Judge status: Accepted
k = int(input())
a, b = map(int, input().split())

tmp = a

if a % k == 0 or b % k == 0:
  print("OK")
else:
  for i in range(a,b):
    if i % k == 0:
      if i <= b:
        print("OK")
        break
      else:
        print("NG")
        break
  else:
    print("NG")
# Judge status: Accepted
n = int(input())
p = list(map(int,input().split()))
i = 0
ans = 0

while i < n:
  if i+1 == p[i]:
    ans += 1
    i += 2
  else:
    i += 1
print(ans)
# Judge status: Wrong Answer
x,a,b = map(int,input().split())
if 0<a-b:
  print('delicious')
elif b-a<x:
  print('safe')
else:
  print('dangerous')
# Judge status: Accepted
ls = list(map(str,input()))
if (ls[2] == ls[3]) and (ls[4] == ls[5]):
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
K = int(input())
A, B = map(int, input().split())

a = int(A/K)
b = int(B/K)

if K == 1:
  print("Yes")
else:
  if a == b:
    print("NG")
  else:
    print("Yes")
# Judge status: Accepted
N=int(input())
if N <= 999:
  print('ABC')
else:
  print('ABD')
# Judge status: Wrong Answer
def Collatz_Problem(n):

    ans = 1
    count = []
    while True:
        if n%2 == 0:
            n = n/2
        else:
            n = 3*n+1
        ans += 1
        if n in count:
            break
        else:
            count.append(n)

    return ans

def main():
    n = int(input())
    print(Collatz_Problem(n))

if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())

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

print(a)
# Judge status: Wrong Answer
N = int(input())
a_list = [int(x) for x in input().split(' ')]
a_list = list(filter(lambda x:x%2 == 0 and (x%3 != 0 and x%5 != 0), a_list))
print(a_list)

if not a_list:
    print('APPROVED')
else:
    print('DENIED')
# Judge status: Accepted

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

A.sort()
ans = 'YES'
for i in range(N-1):
    if A[i] == A[i+1]:
        ans = 'NO'

print(ans)
# Judge status: Accepted
n = int(input())
l = ([int(input()) for j in range(n)])
a = sorted(l)[-1]
b = sorted(l)[-2]

for i in range(n):
  if l[i]==a:
    print(b)
  else:
    print(a)
# Judge status: Accepted
a,b,c=(int(x) for x in input().split())
n=a
ran=b-a+1
counter=0
for num in range(ran):
 if n % c == 0:
  counter += 1
 n += 1
print(counter)
# Judge status: Accepted
n,m=list(map(int,input().split()))
A=list(map(int,input().split()))

if n>=sum(A):
    print(n-sum(A))
else:
    print(-1)
# Judge status: Wrong Answer
x=int(input())
count=0
k=-1
hap=list(map(int,input().split()))
count=max(hap)
k=hap.index(count)
for i in range(1,x):
    hap=list(map(int,input().split()))
    m=-1
    for i in range(len(hap)):
        if i!=k:
            m=max(hap[i],m)
            ano=i
    count+=m
    k=ano
print(count)
# Judge status: Accepted
n,m,*l=[int(i) for i in open(0).read().split()]
print(max(-1,n-sum(l)))
# Judge status: Accepted
def main():
    # 入力
    n = int(input())
    cnt = 0
    for i in range(1, n+1):
        if len(str(i)) % 2 == 1:
            cnt += 1

    print(cnt)


main()
# Judge status: Accepted
N, K = map(int, input().split())
if K > N :
  print(min(abs(N-K),N))
else:
  first = N // K 
  first_1 = N % K 
  print(min(first_1, K - first_1))
# Judge status: Accepted
d = int(input())
print('Christmas'+(25-d)*' Eve')
# Judge status: Accepted
N = int(input())
W = list(map(int,input().split()))
s = 0
i = 0
sw = sum(W)
while s < sw/2:
    s += W[i]
    i += 1
print(min( abs(sum(W[0:i])-sum(W[i:N])) , abs(sum(W[0:i-1])-sum(W[i-1:N])) ))
# Judge status: Accepted
import sys
input = sys.stdin.readline

n, k, q = map(int, input().split())
aq = [int(input()) for _ in range(q)]

point = [0 for _ in range(n+1)]

for i in aq:
    point[i] += 1

for j in range(1, n+1):
    if k - q + point[j] > 0:
        print('Yes')
    else:
        print('No')
# Judge status: Wrong Answer
N=int(input())
L=str(N)
if L[-1]==2 or L[-1]==4 or L[-1]==5 or L[-1]==7 or L[-1]==9:
    print("hon")
elif L[-1]==0 or L[-1]==1 or L[-1]==6 or L[-1]==8:
    print("pon")
else:
    print("bon")
# Judge status: Accepted
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
money = 0
drink = 0
for a,b in ab:
  money += a*b
  drink += b
  if drink >= m:
    money -= (drink-m) * a
    break
print(money)
# Judge status: Wrong Answer
N = input()
list = list(input())
print(len(set(list)))
# Judge status: Accepted
S={s:list(input()) for s in 'abc'}
t='a'
while len(S[t])>0:
  t=S[t].pop(0)
print(t.upper())
# Judge status: Accepted
# C - Repsept
K = int(input())
tmp = 0
ans = -1
for i in range(1,2*K):
    tmp = (10*tmp+7)%K
    if tmp==0:
        ans = i
        break
print(ans)
# Judge status: Wrong Answer
coin = int(input())
coin = coin * 2

if coin == 0:
    print(0)
else:
    print(coin)
# Judge status: Accepted
a, b, c = map(int, input().split())

ans = 'NO'

for i in range(1, b+1):
    if (a*i) % b == c:
        ans = 'YES'
        break

print(ans)
# Judge status: Accepted
from itertools import permutations
n = int(input())
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
for i, l in enumerate(permutations(range(1, n+1)), 1):
  if p == list(l):
    a = i
  if q == list(l):
    b = i
print(abs(a-b))
# Judge status: Accepted
s = input()
key = 'keyence'

if len(s) < len(key):
    print('NO')
else:
    for i in range(len(key)):
        if s[:i] + s[-7+i:] == key:
            print('YES')
            break
    else:
        print('NO')
# Judge status: Accepted
n = int(input())
p = list(map(int, input().split()))

num = p[0]
ans = 1

for i in range(1, n):
    if num >= p[i]:
        ans += 1
        num = p[i]

print(ans)
# Judge status: Accepted
import sys

n = int(input())
s_list = [int(input()) for _ in range(n)]

s_list.sort()

num_sum = sum(s_list)

if num_sum % 10 == 0:
    for num in s_list:
        if num % 10 != 0:
            print(num_sum-num)
            sys.exit()
else:
    print(num_sum)
    sys.exit()

print(0)
# Judge status: Accepted
x = int(input())
if x:
    print(0)
else:
    print(1)
# Judge status: Wrong Answer
N = int(input())
W = [input() for i in range(N)]
flag = True

if len(set(W)) == N:
    for i in range(N - 1):
        if W[i][-1] != W[i + 1][0]:
            flag = False
            break
    if flag:
        print('Yes')
else:
    print('No')
# Judge status: Accepted
n = int(input())
s = list(input())
mod = 10 ** 9 + 7
alph_count = [0] * 200
ans = 0
for i in s:
    m = ord(i)
    alph_count[m] += 1
    c = 1
    for j in range(97, 123):
        if not m == j:
            c *= alph_count[j] + 1
        c %= mod
    ans += c
    ans %= mod
print(ans)
# Judge status: Wrong Answer
k,x = map(int,input().split())

minx,maxx = -1000000, 1000000

if minx + (k-1) > x:
    l = [i for i in range(minx,minx+x+1)]
    print("".join(str(l)))
elif maxx - (k-1) < x:
    l = [i for i in range(maxx-x,maxx+1,-1)]
    print("".join(str(l)))
else:
    l = [i for i in range(x-(k-1),x+(k-1)+1)]
    print("".join(str(l)))
# Judge status: Wrong Answer
n,k = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
print(sum(p[0:n]))
# Judge status: Accepted
a,b=map(int,input().split())
print(max(2*a-1,2*b-1,a+b))
# Judge status: Wrong Answer
s,c=map(int,input().split())
c=c-s*2
if c<=0: print(s)
else: print(c//4+s)
# Judge status: Accepted
from bisect import bisect, bisect_left
 
N=int(input())
L=list(map(int,input().split()))
L.sort()
 
ans = 0
for i in range(N-2):
  a=L[i]
  for k in range(i+1,N-1):
    b=L[k]
    t=bisect_left(L,a+b)
    ans+=t-k-1
print(ans)
# Judge status: Accepted
a, v = list(map(int, input().split()))
b, w = list(map(int, input().split()))
t = int(input())
if a > b:
  a, b = a-v*t, b-w*t
  # a = -1 * 10**9 if a < -1 * 10**9 else a
  # b = -1 * 10**9 if b < -1 * 10**9 else b
  if a <= b:
    print('YES')
  else:
    print('NO')
else:
  a, b = a+v*t, b+w*t
  # a = 10**9 if a > 10**9 else a
  # b = 10**9 if b > 10**9 else b
  if a >= b:
    print('YES')
  else:
    print('NO')
# Judge status: Wrong Answer
n = int(input())
w = list(map(int, input().split()))
for i in range(n):
    ans = min(10**100, abs(sum(w[:i]) - sum(w[i:])))
print(ans)
# Judge status: Wrong Answer
def main():
    s = list(input())
    k = int(input())

    for i in range(len(s)):
        mod = 26-(ord(s[i])-97)%26
        if k >= mod:
            k -= mod
            s[i] = 'a'
        if k == 0:
            break
    
    if k > 0:
        mod = ((ord(s[-1])-97)%26+k)%26
        s[-1] = chr(mod+97)
    print(''.join(s))

if __name__ == '__main__':
    main()
# Judge status: Accepted
n = int(input())
task =[]
for i in range(n):
  task.append(list(map(int,input().split())))

task.sort(key = lambda x:x[1])


total = 0
for j in range(n):
  total += task[j][0]
  if(total > task[j][1]):
    print("No")
    break
  if(j == n-1):
    print("Yes")
# Judge status: Wrong Answer
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


S = input()
print('Yes' if len(set(list(S))) == len(S) else 'No')
# Judge status: Accepted
n, m = map(int, input().split())
constrict = [list(map(int, input().split())) for _ in range(m)]
flag = False
for i in range(10**(n-1)-1, 10**n):
    if len(str(i)) != n:
        continue
    is_correct = True
    for j, k in constrict:
        if str(i)[j-1] != str(k):
            is_correct = False
            break
    if is_correct:
        flag = True
        print(i)
        break
if not flag:
    print(-1)
# Judge status: Accepted
a,b,c,d = map(int, input().split())
if b<=c or d <=a:
  print(0)
  exit()
if a<=c and d<=b:
  print(d-c)
elif a<=c and b<=d:
  print(b-c)
elif c<=a and d<=b:
  print(d-a)
elif c<=a and b<=d:
  print(b-a)
# Judge status: Accepted
x, y = map(int, input().split())

for i in range(x + 1):
    s = i
    t = x - i
    # print(s, t)
    if 2 * s + 4 * t == y:
        print('Yes')
        exit()
print("No")
# Judge status: Accepted
D = int(input())

if D == 25:
    print('Christmas')
elif D == 24:
    print('Christmas Eve')
elif D == 23:
    print('Christmas Eve Eve')
elif D == 22:
    print('Christmas Eve Eve Eve')
# Judge status: Accepted
a,b = map(int,input().split())

if a==1:
  a=14
  
if b==1:
  b=14
  
if a>b:
  print('Alice')
  
elif a<b:
  print('Bob')
  
else:
  print('Draw')
# Judge status: Accepted
import sys
input = sys.stdin.readline

n = int(input())
l = list(map(int,input().split()))

l.sort()
c = 0

import bisect

for i in range(n):
    for j in range(i+1,n):
        ind = bisect.bisect_left(l,l[i]+l[j])
        c += max((ind-j)-1 , 0)
        
print(c)
# Judge status: Accepted
n = int(input())
candy = 0
for i in range(n+1):
    candy += i
print(candy)
# Judge status: Accepted
a,b,c,d = map(int,input().split())
cc = b//c -(a-1)//c
dd = b//d -(a-1)//d
#a,bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

#a,bの最小公倍数
def lcm(a, b):
	return a * b // gcd (a, b)
cd = lcm(c, d)
cdcd = b//cd -(a-1)//cd
print(b-a+1-cc-dd+cdcd)
# Judge status: Wrong Answer
n,m=map(int,input().split())
a=[0]*(n+1)
b=[0]*(n+1)
for i in range(m):
  p,s=input().split()
  p=int(p)
  if a[p]==0:
      if s=="AC":
        a[p]=1
      else:
        b[p]+=1
for i in range(n):
    if a[i]==0:
        b[i]==0
print(sum(a),sum(b))
# Judge status: Accepted
S,W=list(map(int, input().split()))

if S>W:
  print("safe")

else:
  print("unsafe")
# Judge status: Wrong Answer
from collections import Counter

N = int(input())
S = [str(sorted(input())) for _ in range(N)]

C = Counter(S)
ans = 0
for v in C.values():
    # ans += v * (v - 1) // 2
    if v > 1:
        if v == 2:
            ans += 1
        else:
            ans += v
print(ans)
# Judge status: Wrong Answer
n,m = [int(i) for i in input().split()]
if 2 <= n and 2 <= m:
    print((n-2)*(m-2))
elif 2 <= n:
    print((n-2)*m)
elif 2 <= m:
    print(n*(m-2))
else:
    print(0)
# Judge status: Accepted
N,M=map(int,input().split())
way=[0]*(N+1)
for i in range(M):
    a,b=map(int,input().split())
    way[a]+=1
    way[b]+=1
for i in range(N+1):
    if i!=0:
        print(way[i])
# Judge status: Accepted
n=int(input())
dp=[0]*(10**5+1)
dp[0]=1
for i in range(n+1):
  for j in range(100,106):
    dp[i]=max(dp[i],dp[i-j])
if dp[n]==1:
  print(1)
else:
  print(0)
# Judge status: Accepted
A, B, X = map(int, input().split())
if 0 <= X - A <= B:
    print("YES")
else:
    print("NO")
# Judge status: Accepted
n, x = map(int, input().split())
a = list(map(int, input().split()))

last = a[0]
ans = 0
for i in range(1, n):
    if last + a[i] > x:
        num = last + a[i] - x
        ans += num
        last = max(0, a[i] - num)
    else:
        last = a[i]

print(ans)
# Judge status: Wrong Answer
n = int(input())
l = [[i+1]+input().split() for i in range(n) ]


l.sort(key=lambda x: [x[1],-1*x[2]])

for i in range(n):
    print(l[i][0])
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

ans = 1
status = 0
prev = a[0]

for i in a:
    diff = i - prev

    if diff == 0:
        pass
    elif diff > 0:
        if status >= 0:
            status = diff
        else:
            ans += 1
            status = 0
    else:
        if status <= 0:
            status = diff
        else:
            ans += 1
            status = 0

    prev = i

print(ans)
# Judge status: Wrong Answer
import numpy as np
N = int(input())
A = list(map(int,input().split()))
counter = 0
AN = set(A)
A = np.array(A)

for i in AN:
    num = len(A[A < i])
    counter += abs(num - i)

print(counter)
# Judge status: Accepted
n = str(input())
l = len(n)
c = 0
n = "00"+ n
dnow = int(n[l+1])
for i in range(l+1):
  dnext = int(n[l-i])
  if  dnow <= 4:
    c += dnow
  elif dnow == 5:
    if dnext <= 4:
      c += 5
    else:
      dnext += 1
      c += 5
  elif dnow == 10:
    dnext += 1
  else:
    c += 10 - dnow
    dnext += 1
  dnow = dnext
print(c)
# Judge status: Wrong Answer
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, m = na()
x = na()

x.sort()
d = [x[i] - x[i - 1] for i in range(1, m)]
d.sort()
print(sum(d[:m - n]))
# Judge status: Wrong Answer
l = ['MON','TUE','WED','THU','FRI','SAT','SUN']
s = input()

print(6 - l.index(s))
# Judge status: Wrong Answer
from fractions import gcd

n,k=map(int,input().split())

if n == 1 or k == 1:
    print(0)
else:
    print(gcd(n,k))
# Judge status: Wrong Answer
n=int(input())
A=list(map(int,input().split()))

bef=1
ans=0
for i in range(n):
    if A[i]==bef:
        bef+=1
        ans+=1
print(n-ans)
# Judge status: Accepted
import math
N,K=map(int,input().split())

ans = int(math.log(N,K)+1)

print(ans)
# Judge status: Accepted
S = set(list(input()))

A = set(list('abcdefghijklmnopqrstuvwxyz'))

ans = list(A-S)
if len(ans) == 0:
    print('None')
else:
    ans.sort()
    print(ans[0])
# Judge status: Accepted
import sys

h, n = list(map(int, input().split()))
INF = 10 ** 18
dp = [INF] * (20201)
dp[0] = 0
for line in sys.stdin:
    a, b = map(int, line.split())
    for i in range(10000):
        if dp[i] == INF:
            continue
        dp[i + a] = min(dp[i + a], dp[i] + b)
print(min(dp[h:]))
# Judge status: Accepted
C = input()

CC = chr(ord(C) + 1)

print(CC)
# Judge status: Wrong Answer
s = list(input())
l = len(s)
a=0
m=0
for i in range(l):
  if s[i]=='A' or s[i]=='C' or s[i]=='G' or s[i]=='T':
    a+=1
  else:
    a = max(m, a)

print(a)
# Judge status: Wrong Answer
from fractions import Fraction
n = int(input())
a = list(map(int, input().split()))
MOD = 10**9 + 7
ans = 0

for i in range(n):
    ans += Fraction(1, a[i])
print(ans.numerator % MOD)
# Judge status: Accepted
a = list(map(int, input().split()))
print(a[2],a[0],a[1])
# Judge status: Accepted
x,y = map(int,input().split())

f = lambda x,y: y-x if y >= x else float('inf')

print(min(f(x,y), 1+f(-x,y), 2+f(-x,-y), 1+f(x,-y)))
# Judge status: Accepted
def resolve():
    K, N = map(int, input().split())
    A = tuple(map(int, input().split()))
    diff_max = 0
    A_sum = 0

    for i in range(N):
        if i == N-1:
            diff = K-A[i]+A[0]
        else:
            diff = A[i+1] -A[i]

        diff_max = max(diff_max, diff)
        A_sum += diff

    print(A_sum - diff_max)
    
if __name__ == '__main__':
    resolve()
# Judge status: Accepted
from fractions import gcd
A,B,C,D=map(int,input().split())
A-=1
lcm=C*D//gcd(C,D)
print(B-B//C-B//D+B//lcm-(A-A//C-A//D+A//lcm))
# Judge status: Accepted
from math import ceil


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

def f(x):
    cnt = 0
    for a in A:
        cnt += ceil(a / x) - 1
    return True if cnt <= K else False

OK, NG = 10**9, 0
while OK - NG > 1:
    mid = (OK + NG) // 2
    if f(mid):
        OK = mid
    else:
        NG = mid

print(OK)
# Judge status: Accepted
_ = input()
S = input()

print(max([len(set(S[:i]) & set(S[i:])) for i in range(len(S))]))
# Judge status: Accepted
S = input()
print(chr(ord(S)+1))
# Judge status: Accepted
import numpy as np

a,b,c = input()
#print(a)
#print(b)
#print(c)
s = np.zeros(3)
num = 0
if a == '1':
    num = num + 1
if b == '1':
    num = num + 1
if c == '1':
    num = num + 1
print(num)
# Judge status: Wrong Answer
from string import ascii_lowercase
N = int(input())
s = list()

while N > 0: 
	m = N%26 - 1
	s.append(ascii_lowercase[m])
	N = int(N/26)
	
s.reverse()
s = ''.join(s)
print(s)