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

N, Q = map(int, input().split())
S = input()
l_r = []
for i in range(Q):
    l_r.append(list(map(int, input().split())))
    print(S[l_r[i][0]-1: l_r[i][1]].count("AC"))

### FIXED CODE ###

n,q=map(int,input().split())
s=input()
a=[0]*n
for i in range(n):
    if i:
        a[i]=a[i-1]+(s[i-1:i+1]=='AC')
for _ in range(q):
    l,r=map(int,input().split())
    print(a[r-1]-a[l-1])
### BUGGY CODE ###

import sys
N = int(input())
for h in range(1,3501):
    for n in range(1,3501):
        if 4*h*n -N*h -N*n <= 0: continue
        w = N*h*n/(4*h*n -N*h -N*n)
        if not 0<w<=3500: continue 
        if w.is_integer()==True:
            print(h,n,int(w))
            sys.exit()

### FIXED CODE ###

import sys
N = int(input())
for h in range(1,3501):
    for n in range(1,3501):
        if 4*h*n -N*h -N*n <= 0: continue
        w = N*h*n/(4*h*n -N*h -N*n)
        if not 0<w<=3500: continue 
        if w.is_integer()==True:
            print(h,n,int(w))
            sys.exit()
### BUGGY CODE ###

n=int(input())
a = list(map(int,input().split()))
check=[]
ans=0
for i in range(n):
    if [min(i+1,a[i]),max(i+1,a[i])] not in check:
        check.append([min(i+1,a[i]),max(i+1,a[i])])
    else:
        ans+=1
print(ans)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
pair=[]
for i in range(n):
    if i+1 > a[i]:
        w=i+1
        i=a[i]
    else:
        w=a[i]
        i+=1
    pair.append([i,w])
pair.sort()
ans=0
for i in range(len(pair)-1):
    if pair[i]==pair[i+1]:
        ans+=1
print(ans)
### BUGGY CODE ###

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

j=0
c=0
for i in range(len(a)):
    if(a[j]!=j+1):
        del(a[j])
        c+=1
    else:
        j+=1
if(n==c):
    print(-1)
else:
    print(c)


### FIXED CODE ###

n = int(input())
a = input().split()
j=0
c=0
for i in range(len(a)):
    if(int(a[i])!=j+1):
        c+=1
    else:
        j+=1
if(n==c):
    print(-1)
else:
    print(c)
### BUGGY CODE ###

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

D={x:A.count(x) for x in set(A)}

for step in range(Q):
    b,c=map(int,input().split())
    if b not in D.keys():
        print(somme)
        continue

    somme=somme+(c-b)*D[b]
    if c in D.keys():
        D[c]=D[c]+D[b]
    else:
        D[c]=D[b]
    del D[b]    
    print(somme)

### FIXED CODE ###

N=int(input())
A=[int(x) for x in input().split()]
Q=int(input())
somme=sum(A)

from collections import Counter
D=Counter()

for l in A:
    D[l]+=1
    
for step in range(Q):
    b,c=map(int,input().split())

    if b not in D:
        print(somme)
        continue

    somme=somme+(c-b)*D[b]

    D[c]=D[c]+D[b]
    del D[b]    
    print(somme)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N=int(input())
A=[list(map(int,input().split())) for i in range(N)]

B=[[] for i in range(N)]
for i in range(N):
    for j in range(N):
        if A[i][j]==1:
            B[i].append(j)
        
mod=10**9+7

#bitDP
DPLIST=[None]*(2**N)
DPLIST[2**N-1]=1

def dp(NOW,x):

    if DPLIST[NOW]!=None:
        return DPLIST[NOW]

    ANS=0

    for b in B[x]:
        if NOW & (1<<b) ==0:
            ANS=(ANS+dp(NOW+2**b,x+1))%mod

    DPLIST[NOW]=ANS
    return ANS

print(dp(0,0))

### FIXED CODE ###

import sys
input = sys.stdin.readline

N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
mod=10**9+7

#bitDP
DPLIST=[-1]*(2**N)
DPLIST[2**N-1]=1

def dp(NOW,x):

    if DPLIST[NOW]!=-1:
        return DPLIST[NOW]

    ANS=0

    for i in range(N):
        if A[x][i]==1 and NOW & (1<<i) ==0:
            ANS+=dp(NOW+(1<<i),x+1)

    ANS%=mod
    DPLIST[NOW]=ANS
    return ANS

print(dp(0,0))
### BUGGY CODE ###

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

ans = []

for i in range(N):
    temp=0
    if i == 0:
        for j in range(N):
            if j == 0:
                temp += abs(a[1])
            elif j != N-1:
                temp += abs(a[j+1] - a[j])
            else:
                temp += abs(a[j])
    elif i != N-1:
        for j in range(N):
            if j == 0:
                temp += abs(a[0])
            elif j < i:
                temp += abs(a[j]-a[j-1])
            elif j == i:
                temp += abs(a[j+1]-a[j-1])
            elif (j > i) and (j < N-1):
                temp += abs(a[j+1]-a[j])
            else:
                temp += abs(a[j])
    else:
        for j in range(N):
            if j == 0:
                temp += abs(a[0])
            elif j != N-1:
                temp += abs(a[j]-a[j-1])
            else:
                temp += abs(a[j-1])
    ans.append(temp)
      
for x in range(N):
    print(ans[x])

### FIXED CODE ###

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

ans = []

s = 0
for i in range(N):
    if i == 0:
        s += abs(a[0])
    else:
        s += abs(a[i]-a[i-1])
s += abs(a[-1])

for i in range(N):
    if i == 0:
        temp = s  - abs(a[i]) - abs(a[i+1]-a[i]) + abs(a[i+1])
    elif i < N-1:
        temp = s - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]) + abs(a[i+1]-a[i-1])
    else:
        temp = s - abs(a[i]) - abs(a[i]-a[i-1]) + abs(a[i-1])
    ans.append(temp)
for x in range(N):
    print(ans[x])
### BUGGY CODE ###

N, M = map(int, input().split())
Inf = 10000000000
Edge = [[] for i in range(N)]
for i in range(M):
    l, r, d = map(int, input().split())
    Edge[l-1].append((r-1, d))
    Edge[r-1].append((l-1, -d))

Node = [Inf for i in range(N)]
Possible = True
for i in range(N):
    if not Possible:
        break
    elif Node[i] == Inf:
        Node[i] = 0
        Q = [i]
        while Q:
            now = Q.pop(0)
            for e in Edge[now]:
                if Node[e[0]] == Inf:
                    Node[e[0]] = Node[now] + e[1]
                    Q.append(e[0])
                elif Node[now] + e[1] != Node[e[0]]:
                    Possible = False
                    break
print("Yes" if Possible else "No")

### FIXED CODE ###

from collections import deque
N, M = map(int, input().split())
Inf = 10000000000
Edge = [[] for i in range(N)]
for i in range(M):
    l, r, d = map(int, input().split())
    Edge[l-1].append((r-1, d))
    Edge[r-1].append((l-1, -d))
 
Node = [Inf for i in range(N)]
Possible = True
for i in range(N):
    if not Possible:
        break
    elif Node[i] == Inf:
        Node[i] = 0
        Q = deque([i])
        while Q:
            now = Q.popleft()
            for e in Edge[now]:
                if Node[e[0]] == Inf:
                    Node[e[0]] = Node[now] + e[1]
                    Q.append(e[0])
                elif Node[now] + e[1] != Node[e[0]]:
                    Possible = False
                    break
print("Yes" if Possible else "No")
### BUGGY CODE ###

s = input()
l = list(s)
dp = [[0 for i in range(2019)] for i in range(len(l)+1)]
mod = 2019
ans = 0
for i in range(len(s)):
    dp[i+1][int(l[i])] += 1
    for j in range(2019):
        dp[i+1][(10 * j + int(l[i])) % 2019] += dp[i][j]
for i in range(1, len(l)+1):
    ans += dp[i][0]
print(ans)

### FIXED CODE ###

s = input()
l = []
n = len(s)
mod = 2019
s = list(s)
s = list(map(int, s))
l.append(s[-1])
for i in range(n-2, -1, -1):
    tmp = l[-1]
    l.append((tmp+s[i] * pow(10, n - i - 1, 2019))%2019)
cnt = [0 for i in range(2019)]
cnt[0] += 1
for i in range(len(l)):
    cnt[l[i]] += 1
ans = 0
for i in range(len(cnt)):
    ans += cnt[i]*(cnt[i]-1)//2
print(ans)
### BUGGY CODE ###

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007
sys.setrecursionlimit(1000000)

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    n,m = LI()
    a = LIR(m)
    d = [0 for i in range(n+1)]
    a.sort()
    for i in range(m):
        d[a[i][0]] = i
    for i in range(n):
        d[i+1] = max(d[i],d[i+1])
    for i in range(n):
        a.sort(key = lambda x:x[1])
        mi = a[0][1]-1
        l = d[mi]-(m-len(a))
        a.sort(key = lambda x:x[0])
        a = a[l+1:]
        if len(a) == 0:
            print(i+1)
            quit()
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()


### FIXED CODE ###

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007
sys.setrecursionlimit(1000000)

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    n,m = LI()
    a = LIR(m)
    a.sort(key = lambda x:x[1])
    x = 0
    ans = 0
    for i in range(m):
        if a[i][0] >= x:
            x = a[i][1]
            ans += 1
    print(ans)
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()
### BUGGY CODE ###

#  --*-coding:utf-8-*--

def bit_inc(bit, x, n):
    m = len(bit)
    
    bit[x-1] += n
    b = 1

    while b < m:
        if x & b:
            x += b
            if x <= m:
                bit[x-1] += n

        b <<= 1



def bit_count(bit, x):
    m = len(bit)

    n = 0
    b = 1

    while b < m:
        if x & b:
            n += bit[x-1]
            x -= b

        b <<= 1

    return n

N = int(input())
bits = [[0]*(N+1) for _ in range(26)]

S = list(input())
for i, s in enumerate(S):
    bit_inc(bits[ord(s) - 97], i+1, 1)

Q = int(input())
for _ in range(Q):
    q1,q2, q3 = input().split()
    q2 = int(q2)

    if q1 == '1':
        s0 = S[q2-1]
        if s0 != q3:
            S[q2-1] = q3
            bit_inc(bits[ord(s0) - 97], q2, -1)
            bit_inc(bits[ord(q3) - 97], q2, 1)
    else:
        cnt = 0
        q3 = int(q3)
        for bit in bits:
            t = bit_count(bit, q3)

            if q2 > 1:
                t -= bit_count(bit, q2-1)

            if t > 0:
                cnt += 1

        print(cnt)


### FIXED CODE ###

#  --*-coding:utf-8-*--

import bisect

N = int(input())
indexess = [[] for _ in range(26)]

S = list(input())
for i, s in enumerate(S):
    indexess[ord(s) - 97].append(i)


Q = int(input())
for _ in range(Q):
    q1,q2, q3 = input().split()
    q2 = int(q2)

    if q1 == '1':
        s0 = S[q2-1]
        if s0 != q3:
            S[q2-1] = q3
            
            indexes = indexess[ord(s0) - 97]
            del indexes[bisect.bisect_left(indexes, q2-1)]
            bisect.insort(indexess[ord(q3) - 97], q2-1)

    else:
        cnt = 0
        q3 = int(q3)
        for indexes in indexess:
            
            if bisect.bisect_left(indexes, q2-1) < bisect.bisect_right(indexes, q3-1):
                cnt += 1

        print(cnt)
### BUGGY CODE ###

N,P = map(int, input().split())
S = input()

if P == 2 or P == 5:
    ans = 0
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += i+1
    print(ans)
else:
    mod_cnt = [0]*P
    mod_cnt[0] = 1
    for i in range(N):
        mod = int(S[i:]) % P
        mod_cnt[mod] += 1
    ans = 0
    for cnt in mod_cnt:
        ans += (cnt * (cnt-1)) // 2
    print(ans)


### FIXED CODE ###

N,P = map(int, input().split())
S = input()

if P == 2 or P == 5:
    ans = 0
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += i+1
    print(ans)
else:
    mod_cnt = [0]*P
    mod_cnt[0] = 1
    k = 0.1
    t = 0
    for i in range(1, N+1):
        k = int(k * 10) % P
        t = (t + k * int(S[-i])) % P
        mod_cnt[t] += 1
    ans = 0
    for cnt in mod_cnt:
        ans += (cnt * (cnt-1)) // 2
    print(ans)
### BUGGY CODE ###

from collections import defaultdict
n, m = map(int, input().split())

city_to_pref, city_to_birth, pref_to_birth_list = {}, {}, defaultdict(list)
for i in range(m):
    pref, birth = map(int, input().split())
    city_to_pref[i] = pref
    city_to_birth[i] = birth
    pref_to_birth_list[pref].append(birth)


def get_city_index(i):
    pref = city_to_pref[i]
    birth = city_to_birth[i]
    years = pref_to_birth_list[pref]
    return years.index(birth)


def give_id(i):
    p = city_to_pref[i]
    x = get_city_index(i) + 1
    return '{:0=6}{:0=6}'.format(p, x)


for pref, births in pref_to_birth_list.items():
    pref_to_birth_list[pref] = sorted(births)

for i in range(m):
    print(give_id(i))

### FIXED CODE ###

from collections import defaultdict, Counter
n, m = map(int, input().split())

city_to_pref, city_to_birth, pref_to_birth_list = {}, {}, defaultdict(list)
pref_counter = Counter()
city_id = {}
for i in range(m):
    pref, birth = map(int, input().split())
    city_to_pref[i] = pref
    city_to_birth[i] = birth
    pref_to_birth_list[pref].append(birth)


def get_city_index(i, pref):
    birth = city_to_birth[i]
    return pref_birth_to_id[pref][birth]


def give_id(i):
    p = city_to_pref[i]
    x = get_city_index(i, p) + 1
    return '{:0=6}{:0=6}'.format(p, x)


pref_birth_to_id = defaultdict(lambda : defaultdict(int))
for pref, births in pref_to_birth_list.items():
    for i, birth in enumerate(sorted(births)):
        pref_birth_to_id[pref][birth] = i

for i in range(m):
    print(give_id(i))
### BUGGY CODE ###

mod = 10 ** 9 + 7

s = input()
dp = [[0 for _ in range(13)] for _ in range(len(s) + 1)]
for i in range(len(s) - 1,  -1, -1):
    digit = len(s) - i - 1
    ddd = 10 ** digit
    if digit == 0:
        if s[i] != '?':
            dp[digit + 1][int(s[i])] += 1
        else:
            for j in range(10):
                dp[digit + 1][j] += 1    
    elif s[i] != '?':    
        s_i = (int(s[i]) * ddd) % 13
        for k in range(13):
            dp[digit + 1][(s_i + k) % 13] += dp[digit][k]
    else:        
        for j in range(10):
            s_i = (ddd * j) % 13
            for k in range(13):
                dp[digit + 1][(s_i + k) % 13] += dp[digit][k]
print(dp[len(s)][5] % mod)

### FIXED CODE ###

mod = 10 ** 9 + 7

s = input()
dp = [0] * 13
dp[0] = 1
for i in range(len(s)):
    dp2 = [0] * 13
    for j in range(10):
        if (s[i] == '?') | (s[i] == str(j)):
            for k in range(13):
                dp2[(10 * k + j) % 13] += dp[k]
                dp2[(10 * k + j) % 13] %= mod
    dp = dp2
print(dp[5])
### BUGGY CODE ###

n = int(input())
a = [(A, i) for i, A in enumerate(map(int, input().split()))]

a.sort(reverse=True)
INF = float('inf')
#print(a)

dp = [[-INF]*(n+1) for _ in range(n+1)]
dp[0][0] = 0

for num, (A, pos) in enumerate(a):
    #print("="*5, num, "="*5)
    for i in range(num+1):
        j = num - i
        dp[i+1][j] = max(dp[i+1][j], dp[i][j] + A*abs(pos-i))  # 左からi番目の時
        dp[i][j+1] = max(dp[i][j+1], dp[i][j] + A*abs((n-1-j)-pos))  # 右からj番目の時

        # print("="*3, i, "="*3)
        # for k in range(len(dp)):
        #     print(dp[k])
    

ans = 0
for i in range(n+1):
    j = n-i
    ans = max(ans, dp[i][j])
    # print(f"i = {i}")
    # print(f"j = {j}")
    # print(max(ans, dp[i][j]))

print(ans)

### FIXED CODE ###

def main():
  N = int(input())
  INF = float('inf')
  A = [(i+1, a) for i, a in enumerate(map(int, input().split()))]
  A = sorted(A, key=lambda x: x[1], reverse = True)

  dp = [[-INF] * (N+1) for _ in range(N+1)]
  dp[0][0] = 0

  for s in range(1, N+1):
    for l in range(s+1):
      r = s - l
      dp[l][r] = max(dp[l-1][r] + A[s-1][1] * abs(A[s-1][0]-l), dp[l][r-1] + A[s-1][1] * abs(N-r+1-A[s-1][0]))
    
  ans = 0
  for m in range(N):
    if(dp[m][N-m] > ans):
      ans = dp[m][N-m]
    
  print(ans)

main()
### BUGGY CODE ###

n,m = map(int,input().split())
p = list(map(int,input().split()))
xy = [list(map(int,input().split())) for _ in range(m)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


uf = UnionFind(n)
ans = 0
for x,y in xy:
    uf.union(x-1,y-1)
for v in uf.all_group_members().values():
    li = []
    for i in v:
        li.append(p[i]-1)
    ans += len(set(v)&set(li))

print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

def main():
    n,m = map(int,input().split())
    p = list(map(int,input().split()))
    xy = [list(map(int,input().split())) for _ in range(m)]

    class UnionFind(object):
        def __init__(self, n=1):
            self.par = [i for i in range(n)]
            self.rank = [0 for _ in range(n)]
            self.size = [1 for _ in range(n)]

        def find(self, x):
            if self.par[x] == x:
                return x
            else:
                self.par[x] = self.find(self.par[x])
                return self.par[x]

        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)
            if x != y:
                if self.rank[x] < self.rank[y]:
                    x, y = y, x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1
                self.par[y] = x
                self.size[x] += self.size[y]

        def all_group_members(self):
            return_list = [list() for i in range(n)]
            for i in range(n):
              return_list[self.find(i)].append(i)
            return return_list

    uf = UnionFind(n)
    ans = 0
    for x,y in xy:
        uf.union(x-1,y-1)
    for v in uf.all_group_members():
        set1 = set()
        for i in v:
            set1.add(p[i]-1)
        ans += len(set(v)&set1)

    print(ans)

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

import sys
inf=1000002
sys.setrecursionlimit(inf)
from collections import deque
h,w,k=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
c=[input() for i in range(h)]
dp=[[inf if c[i][j]=="." else -1 for j in range(w)] for i in range(h)]
now=deque()
now.append([x1-1,y1-1])
def bfs(d):
    global h,w,k,dp,now
    l=len(now)
    if l==0:
        return
    for i in range(l):
        x,y=now.popleft()
        for j in range(1,min(k+1,w-y)):
            if dp[x][y+j]==inf:
                dp[x][y+j]=d
                now.append([x,y+j])
            if dp[x][y+j]==-1:
                break
        for j in range(1,min(k+1,y+1)):
            if dp[x][y-j]==inf:
                dp[x][y-j]=d
                now.append([x,y-j])
            if dp[x][y-j]==-1:
                break
        for j in range(1,min(k+1,h-x)):
            if dp[x+j][y]==inf:
                dp[x+j][y]=d
                now.append([x+j,y])
            if dp[x+j][y]==-1:
                break
        for j in range(1,min(k+1,x+1)):
            if dp[x-j][y]==inf:
                dp[x-j][y]=d
                now.append([x-j,y])
            if dp[x-j][y]==-1:
                break
    bfs(d+1)
bfs(1)
print(dp[x2-1][y2-1] if dp[x2-1][y2-1]!=inf else -1)

### FIXED CODE ###

import sys
inf=1000002
sys.setrecursionlimit(inf)
from collections import deque
h,w,k=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
c=[input() for i in range(h)]
dp=[[inf if c[i][j]=="." else -1 for j in range(w)] for i in range(h)]
now=deque()
now.append([x1-1,y1-1])
dp[x1-1][y1-1]=0
#kの更新が遅い
def bfs(d):
    global h,w,k,dp,now,x2,y2
    l=len(now)
    if l==0:
        return
    dp_sub=deque()
    cand=set()
    for i in range(l):
        x,y=now.popleft()
        for j in range(1,min(k+1,w-y)):
            if dp[x][y+j]==inf:
                dp_sub.append([x,y+j,d])
                #dp[x][y+j]=d
                cand.add((x,y+j))
                #now.append([x,y+j])
            else:
                break
        for j in range(1,min(k+1,y+1)):
            if dp[x][y-j]==inf:
                dp_sub.append([x,y-j,d])
                #dp[x][y-j]=d
                cand.add((x,y-j))
                #now.append([x,y-j])
            else:
                break
        for j in range(1,min(k+1,h-x)):
            if dp[x+j][y]==inf:
                dp_sub.append([x+j,y,d])
                #dp[x+j][y]=d
                cand.add((x+j,y))
                #now.append([x+j,y])
            else:
                break
        for j in range(1,min(k+1,x+1)):
            if dp[x-j][y]==inf:
                dp_sub.append([x-j,y,d])
                #dp[x-j][y]=d
                cand.add((x-j,y))
                #now.append([x-j,y])
            else:
                break
    while dp_sub!=deque([]):
        e=dp_sub.popleft()
        dp[e[0]][e[1]]=e[2]
    for i in cand:
        now.append(i)
    bfs(d+1)
bfs(1)
print(dp[x2-1][y2-1] if dp[x2-1][y2-1]!=inf else -1)
### BUGGY CODE ###

import numpy as np

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

dp = [0]*n
h = np.array(h)
dp = np.array(dp)
dp[1] = abs(h[0] - h[1])
for i in range(2, n):
    if k == 1:
        dp[i] = dp[i-1] + abs(h[i-1] - h[i])
    elif i < k:
        dp[i] = np.min(dp[:i] + np.abs(h[:i] - np.full(h[:i].size, h[i])))
    else:
        dp[i] = np.min(dp[i-k:i] + np.abs(h[i-k:i] - np.full(h[i-k:i].size, h[i])))
        
print(dp[-1])


### FIXED CODE ###

import numpy as np

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

dp = [10**9]*(n+k+2)
h = np.array(h)
h = np.insert(h, len(h), np.zeros(k+2))
dp = np.array(dp)
dp[0] = 0

for i in range(n):
    dp[i+1 : i+k+1] = np.minimum(dp[i+1:i+k+1], dp[i] + np.abs(h[i+1:i+k+1] - h[i]))

print(dp[n-1])
### BUGGY CODE ###

n=int(input())
ans=0
for c in range(1,n+1):
    for a in range(1,n+1):
        for b in range(1,n+1):
            if n-c==a*b:
                ans+=1
print(ans)

### FIXED CODE ###

n=int(input())
ans=0
for a in range(1,n):
    ans+=(n-1)//a
print(ans)