CodeEff/ECCO huggingface dataset:
# Original solution
import sys
readline = sys.stdin.readline

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

dp = [[0] * (N + 1) for i in range(N + 1)]

# [i,j)
for l in range(1, N + 1):
  for i in range(N - l + 1):
    j = i + l
    
    if (N - l) % 2 == 0: # 先手
      dp[i][j] = max(dp[i + 1][j] + A[i], dp[i][j - 1] + A[j - 1])
    else:
      dp[i][j] = min(dp[i + 1][j] - A[i], dp[i][j - 1] - A[j - 1])
    
print((dp[0][N]))

# Optimized solution
import sys
readline = sys.stdin.readline

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

# dp[l][r] = [l:r)の区間から起こり得るX - Yの最大値
# [N - 区間の長さ] = 偶数のとき、次に取るのは先手

dp = [[0] * (N + 1) for i in range(N + 1)]

for k in range(1, N + 1): # 区間の長さ
  for i in range(N + 1 - k):
    if (N - k) % 2 == 0: # 先手番
      dp[i][i + k] = max(dp[i + 1][i + k] + A[i], dp[i][i + k - 1] + A[i + k - 1])
    else: # 後手番
      dp[i][i + k] = min(dp[i + 1][i + k] - A[i], dp[i][i + k - 1] - A[i + k - 1])

print((dp[0][N]))
# Original solution
import sys

read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)


def solve():
    N, *a = list(map(int, read().split()))
    a = tuple(a)
    INF = float('inf')
    memo = [[INF] * N for _ in range(N)]

    def f(i, j):
        if memo[i][j] != INF:
            return memo[i][j]
        n = j - i + 1
        n %= 2
        if i == j:
            if n == r:
                s = a[i]
            else:
                s = -a[i]
            memo[i][j] = s
            return s
        if n == r:
            s = max(f(i, j - 1) + a[j], f(i + 1, j) + a[i])
        else:
            s = min(f(i, j - 1) - a[j], f(i + 1, j) - a[i])
        memo[i][j] = s
        return s

    r = N % 2
    f(0, N - 1)
    return memo[0][N - 1]


print((solve()))


# Optimized solution
import sys

read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)


def solve():
    n, *a = list(map(int, read().split()))
    a = tuple(a)
    dp = [[0] * n for _ in range(n)]
    for i in range(n):
        dp[i][i] = a[i]
    for i in range(n - 2, -1, -1):
        for j in range(i + 1, n):
            L = a[i] - dp[i + 1][j]
            R = a[j] - dp[i][j - 1]
            if L > R:
                dp[i][j] = L
            else:
                dp[i][j] = R
    return dp[0][n - 1]


print((solve()))
# Original solution
import sys
sys.setrecursionlimit(10000)
n = int(eval(input()))
*A, = list(map(int, input().split()))
DP = [[None for j in range(n+1)] for i in range(n)]
def dp(i, j):
    if i == j:
        return 0
    if DP[i][j] != None:
        return DP[i][j]
    DP[i][j] = max(A[i]-dp(i+1, j), A[j-1]-dp(i, j-1))
    return DP[i][j]
print((dp(0, n)))


# Optimized solution
n = int(eval(input()))
*A, = list(map(int, input().split()))
DP = [[0 for j in range(n+1)] for i in range(n+1)]
for l in range(1, n+1):
    for i in range(n-l+1):
        j = i+l
        DP[i][j] = max(A[i]-DP[i+1][j], A[j-1]-DP[i][j-1])
print((DP[0][n]))
# Original solution
import math
from fractions import Fraction
mod = 998244353
n = int(eval(input()))
p = [list(map(int, input().split())) for i in range(n)]
pow2 = [2**i % mod for i in range(n + 1)]
used = [[False] * n for i in range(n)]
ret = (pow2[n] - 1 - n - n * (n - 1) / 2) % mod
for i in range(n):
    for j in range(i):
        if used[i][j]:
            continue
        inline = [i, j]
        for k in range(n):
            if k == i or k == j:
                continue
            if (p[i][1] - p[k][1]) * (p[j][0] - p[k][0]) == (p[j][1] - p[k][1]) * (p[i][0] - p[k][0]):
                inline.append(k)
        for k in range(len(inline)):
            for l in range(len(inline)):
                used[inline[k]][inline[l]] = True
        v = len(inline)
        ret = (ret + mod - pow2[v] + 1 + v + v * (v - 1) // 2) % mod
print((int(ret)))


# Optimized solution
import math
mod = 998244353
n = int(eval(input()))
p = [list(map(int, input().split())) for i in range(n)]
pow2 = [1]
for i in range(n):
    pow2.append(pow2[-1] * 2 % mod)
used = [[False] * n for i in range(n)]
ret = (pow2[n] - 1 - n - n * (n - 1) / 2) % mod
for i in range(n):
    for j in range(i):
        if used[i][j]:
            continue
        inline = [i, j]
        for k in range(n):
            if k == i or k == j:
                continue
            if (p[i][1] - p[k][1]) * (p[j][0] - p[k][0]) == (p[j][1] - p[k][1]) * (p[i][0] - p[k][0]):
                inline.append(k)
        for k in range(len(inline)):
            for l in range(len(inline)):
                used[inline[k]][inline[l]] = True
        v = len(inline)
        ret = (ret + mod - pow2[v] + 1 + v + v * (v - 1) // 2) % mod
print((int(ret)))
# Original solution
A, B = list(map(int, input().split()))

c = 0
tmp = 1
while tmp < B:
    c += 1
    tmp = (A - 1) * (c - 1) + A

print(c)


# Optimized solution
def main():
    A, B = list(map(int, input().split()))
    if B == 1:
        print((0))
        exit()
    
    cnt = A
    tap = 1
    while True:
        if cnt >= B:
            print(tap)
            exit()
        cnt += (A - 1)
        tap += 1




if __name__ == "__main__":
    main()
# Original solution
n,m = list(map(int,input().split()))
# n = int(input())
# s = input()
# t = input()
ans = 0
while m > 1:
    m -= n - 1
    ans += 1
print(ans)

# Optimized solution
a, b = list(map(int, input().split()))
print(((b - 1) // (a - 1) + min(1, (b - 1) % (a - 1))))
# Original solution
import sys
from pprint import pprint

def solve(a, b):
    ans = 0
    emp = 1
    while emp < b:
        emp += a - 1
        ans += 1
    print(ans)

if __name__ == '__main__':
  a, b = list(map(int, sys.stdin.readline().strip().split(" ")))
  solve(a, b)


# Optimized solution
import sys

A, B = list(map(int, sys.stdin.readline().split()))
print(((B - A - 1) // (A-1) + 2))
# Original solution
A, B = list(map(int, input().split()))
k = 1
while k < B:
    k += A - 1
if A == 2 :
    print((k-1))
else:
    print((k//(A - 1)))

# Optimized solution
A, B = list(map(int, input().split()))
k = 1
s = 0
while k < B:
    k += A - 1
    s += 1
print(s)
# Original solution
# -*- coding: utf-8 -*-
"""
Created on Sun Sep  1 20:21:49 2019

@author: Yamazaki Kenichi
"""

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

ans = (B-A-1)//(A-1) + 1 + 1

print(ans)    
    



# Optimized solution
A, B = list(map(int,input().split()))

ans = (B-1-1)//(A-1)+1
print(ans)
# Original solution
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


A,B = MI()

print(((B+A-3)//(A-1)))


# Optimized solution
import sys
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))


A,B = MI()
print(((B+A-3)//(A-1)))
# Original solution
import math
A, B = list(map(int, input().split()))
if B == 1:
    print((0))
elif A >= B:
    print((1))
else:
    print((math.ceil((B - 1) / (A - 1))))


# Optimized solution
import math
A, B = list(map(int, input().split()))
if B == 1:
    print((0))
elif A >= B:
    print((1))
else:
    print((math.ceil((B - A) / (A - 1)) + 1))
# Original solution
a, b = list(map(int,input().split()))
for i in range(b):
    if 1 + (a-1)*i >= b:
        print(i)
        break

# Optimized solution
a, b = list(map(int,input().split()))
i = 0
while True:
    if 1 + (a-1)*i >= b:
        print(i)
        break
    i += 1
# Original solution
a,b=list(map(int,input().split()))

import math

socket=0;ans=0
if b==1:
  ans=0
else:
  while (True):
    if socket+a >= b:
      ans+=1
      break
    socket+=a-1
    ans+=1

print(ans)

# Optimized solution
a,b=list(map(int,input().split()))

import math

socket=1;ans=0

while (True):
  if socket >= b:
    break
  socket-=1
  socket+=a
  ans+=1

print(ans)
# Original solution
a,b = list(map(int,input().split()))
ans = 0
c = 1
while c < b:
    ans += 1
    c = c-1+a
print(ans)





# Optimized solution
a,b=list(map(int,input().split()))
print(((b-1+a-1-1)//(a-1)))
# Original solution
# ABC 139: B – Power Socket
from math import ceil

a, b = [int(s) for s in input().split()]
print((ceil((b - 1) / (a - 1))))

# Optimized solution
# ABC 139: B – Power Socket
A, B = [int(s) for s in input().split()]

taps = 0

while (A - 1) * taps + 1 < B:
    taps += 1

print(taps)
# Original solution
a,b = list(map(int,input().split()))
ans = 1
count = 0
while ans < b:
    ans = (ans-1)+a
    count += 1
print(count)

# Optimized solution
a,b = list(map(int,input().split()))
ans = 1
count = 0
while ans<b:
    ans += (a-1)
    count += 1
print(count)
# Original solution
a,b = list(map(int, input().split()))
from math import ceil
print((ceil( (b-1) / (a-1) ) ))


# Optimized solution
def resolve():
    a,b = list(map(int, input().split()))

    tmp = 1
    cnt = 0
    while tmp < b:
        tmp -= 1
        cnt += 1
        tmp += a
    print(cnt)

if __name__ == '__main__':
    resolve()
# Original solution
A,B = list(map(int,input().split()))
ans=1
cnt=0
while B > ans:
	ans+=A-1
	cnt+=1
print(cnt)

# Optimized solution
import math
A,B = list(map(int,input().split()))
print((math.ceil((B - A) / (A - 1)) + 1))
# Original solution
import math
(a,b) = list(map(int, input().split()))

print((math.ceil(((b-a)/(a-1) + 1))))

# Optimized solution
A, B = [int(A) for A in input().split()] 
socket = 0
count = 0
if B==1 :
    count=0
elif B != 0 :
    while socket < B :
        if socket + A < B :
            socket = socket + A - 1
            count += 1
        elif socket+A >= B :
            socket = socket + A
            count += 1
print(count)
# Original solution
import math 
a,b=list(map(int,input().split()))
print((math.ceil((b-1)/(a-1))))


# Optimized solution
a,b=list(map(int,input().split()))
ans,num=0,1
while num<b:
    num-=1
    num+=a
    ans+=1
print(ans)
# Original solution
from sys import stdin
import queue
import sys
import math

a,b=list(map(int,input().split()))
print((math.ceil((b-1)/(a-1))))


# Optimized solution
import math
 
a,b=list(map(int,input().split()))
print((math.ceil((b-1)/(a-1))))
# Original solution
import sys
input = sys.stdin.readline
a,b = list(map(int, input().split()))

cnt = 1
while True:
  if b<= 1:
    cnt = 0
  elif b <= (a-1)*cnt+1:
    break
  cnt += 1
  
print(cnt)

# Optimized solution
import sys
input = sys.stdin.readline
a,b = list(map(int, input().split()))

cnt = 1
while True:
  if b<= 1:
    cnt = 0
    break
  elif b <= (a-1)*cnt+1:
    break
  cnt += 1
  
print(cnt)
# Original solution
a, b = list(map(int, input().split()))

now = 1
ans = 0
while now < b:
  ans += 1
  now += a-1
print(ans)


# Optimized solution
a, b = list(map(int, input().split()))
tmp = (b-1)/(a-1)
if tmp - int(tmp) == 0:
  print((int(tmp)))
else:
  print((int(tmp)+1))
# Original solution
a, b = list(map(int, input().split()))

print((-(-(b-a)//(a-1)) + 1))


# Optimized solution
# 2:50
a, b = list(map(int, input().split()))
if b == 1:
    print((0))
    exit()

if a >= b:
    print((1))
else:
    b -= a
    cnt = 1
    while (b > 0):
        b -= (a - 1)
        cnt += 1
    print(cnt)
# Original solution
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return list(map(fn, readline().split()))


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    a, b = geta(int)

    if b == 1:
        print((0))
        exit()

    n = 1
    while a * n - n + 1 < b:
        n += 1

    print(n)


if __name__ == "__main__":
    main()

# Optimized solution
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return list(map(fn, readline().split()))


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    a, b = geta(int)

    tot = 1
    ans = 0
    while tot < b:
        ans += 1
        tot += a - 1

    print(ans)


if __name__ == "__main__":
    main()
# Original solution
from copy import deepcopy
from math import ceil
if __name__ == "__main__":

    a = list(map(int, input().split()))
    n = deepcopy(a[0])
    i = 1
    if a[0] == a[1]: print(i)
    elif a[1] == 1: print((0))
    elif a[0] >= a[1]: print(i)
    else:
        while True:
            i += 1
            n += a[0] - 1
            if n >= a[1]:
                print(i)
                break

# Optimized solution
#n = input()
a = list(map(int, input().split()))
#b = list(map(int, input().split()))
#c = list(map(int, input().split()))
r = 1
c = 0
if a[1] == 1:
    print((0))
elif a[0] == a[1]:
    print((1))
else:
    while r < a[1]:
        c += 1
        r -= 1
        r += a[0]
    print(c)
# Original solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    s = S()
    t = S()
    ans = 0
    for i in range(len(s)):
        if s[i] == t[i]:
            ans += 1
    print(ans)
    return

#B
def B():
    a,b = LI()
    for i in range(10000):
        if 1+i*a-i >= b:
            print(i)
            return
    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

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


# Optimized solution
import math
a,b = [int(x) for x in input().split()]
print((math.ceil((b-1)/(a-1))))
# Original solution
import math
a,b=list(map(int,input().split()))
print((math.ceil((b-1)/(a-1))))

# Optimized solution
a,b=list(map(int,input().split()))
print((-(-(b-1)//(a-1))))
# Original solution
# -*- coding: utf-8 -*-
a,b = list(map(int, input().split()))

res = 0
cnt = 1
while cnt<b:
    cnt += a-1
    res += 1
print(res)


# Optimized solution
a,b = list(map(int, input().split()))

s = 1
cnt = 0
while s<b:
    s += a-1
    cnt += 1

print(cnt)
# Original solution
a, b = list(map(int, input().split()))
print((0 if b == 1 else ((b - 1) + (a - 2)) // (a - 1)))


# Optimized solution
a, b = list(map(int, input().split()))
print((((b - 1) + (a - 2)) // (a - 1)))
# Original solution
import math
a, b = list(map(int, input().split()))
print((math.ceil((b-1)/(a-1))))

# Optimized solution
a, b = list(map(int, input().split()))

n = 0
while a*n-(n-1) < b:
    n += 1

print(n)
# Original solution
import sys

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

if B == 1:
    print((0))
    sys.exit()

ans = 1
taps = A
while True:
    if B <= taps:
        break
    ans += 1
    taps += A - 1

print(ans)

# Optimized solution
A, B = list(map(int, input().split()))

ans = 0
taps = 1
while taps < B:
    taps += A - 1
    ans += 1

print(ans)
# Original solution
a, b = list(map(int, input().split()))
b -= 1
a = (b + (a - 2)) // (a - 1)
print(a)

# Optimized solution
a, b = list(map(int, input().split()))

# b -= a
# counter = 1
# while b > 0:
#     b -= a - 1
#     counter += 1

# print(counter)

sum_tap = 1

for i in range(100):
    if sum_tap >= b:
        print(i)
        break
    sum_tap += a - 1
# Original solution
A, B = list(map(int,input().split()))


for i in range(21):
    if ((A - 1) * (i - 1)) + A >= B:
        print(i)
        exit()

# Optimized solution
A, B = list(map(int, input().split()))

for i in range(0, 21):
    ans = i * ( A - 1 ) + 1
    if ans >= B:
        print(i)
        exit()
# Original solution
def slove():
    import sys
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    t = 1
    cnt = 0
    while True:
        if t >= b:
            print(cnt)
            exit()
        else:
            t += a
            t -= 1
            cnt += 1


if __name__ == '__main__':
    slove()


# Optimized solution
def slove():
    import sys
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    d = a - 1
    print(((b - 1 + d - 1) // d))


if __name__ == '__main__':
    slove()
# Original solution
A, B = list(map(int,input().split()))
puragu = 1
if B == 1:
  print((0))
  exit()
if A >= B:
  print((1))
  exit()

result = 0

while puragu < B:
  puragu += A-1
  result += 1

print(result)


# Optimized solution
A, B = list(map(int, input().split()))
tap = 1
count = 0
while tap < B:
    tap += A - 1
    count += 1

print(count)
# Original solution
a, b = [int(i) for i in input().split()]
b-=1
c=0
while b>0:
    b-=a-1
    c+=1
print(c)

# Optimized solution
a, b = list(map(int, input().split()))
ans = 0
tmp = 0

if b == 1:
    print((0))
    exit()

for i in range(10 ** 9):
    ans += 1
    tmp += a
    if b <= tmp:
        break
    else:
        tmp -= 1
print(ans)
# Original solution
AB = input().split()
A,B = int(AB[0]),int(AB[1])

count = 0
unused = 1
while unused < B:
  unused += A - 1
  count += 1
  
print(count)

# Optimized solution
a,b=list(map(int,input().split()))
t=1
ans=0
while t<b:
  t += a-1
  ans += 1
print(ans)
# Original solution
a,b = list(map(int,input().split()))
res = 0
c = 1
while c < b:
    c += a - 1
    res += 1
print(res)

# Optimized solution
a,b = list(map(int,input().split()))

ans = 0
tap = 1
while tap < b:
    ans += 1
    tap += a - 1
print(ans)
# Original solution
import math

a, b = list(map(int, input().split(' ')))

print((math.ceil((b - 1) / (a - 1))))


# Optimized solution
a, b = list(map(int, input().split(' ')))

print((-(-(b-1) // (a-1))))
# Original solution
import math
a, b = list(map(int, input().split()))
i = 0
s = 1
while b > s:
    s += a-1
    i += 1
print(i)

# Optimized solution
import math
a, b = list(map(int, input().split()))
print((math.ceil((b-1)*1.0/(a-1))))
# Original solution
A, B = list(map(int, input().split()))

ans = 0
k = 1
while k < B:
    ans += 1
    k += A - 1
print(ans)

# Optimized solution
a,b=list(map(int, input().split()))
k=1
for i in range(1000):
    if k>=b:
        print(i)
        break
    k = k - 1 + a
# Original solution
a,b=list(map(int,input().split()))
sum=1
tap=0
while sum<b:
    sum+=a-1
    tap+=1
print(tap)

# Optimized solution
a,b=list(map(int,input().split()))
con=1
ans=0
while con<b:
    con+=a-1
    ans+=1
print(ans)
# Original solution
A, B = list(map(int, input().split()))
 
if (B-1)%(A-1) == 0:
  print((int((B-1)/(A-1))))
else:
  print((int((B-1)//(A-1) +1)))

# Optimized solution
A, B = list(map(int, input().split()))
 
if (B-1)%(A-1) == 0:
  print((int((B-1)/(A-1))))
else:
  print(((B-1)//(A-1) +1))
# Original solution
a,b = list(map(int,input().split()))
sumA = a
count  =1
ans = 0
while count < b:
    count -=1
    count +=a
    ans +=1
print(ans)

# Optimized solution
a,b = list(map(int,input().split()))
count  =1
ans = 0
while count < b:
    count -=1
    count +=a
    ans +=1
print(ans)
# Original solution
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return eval(input())

def main():
  a,b=LI()
  c=1
  ans=0
  while True:
    if c>=b:
      return ans
    ans+=1
    c-=1
    c+=a

# main()
print((main()))


# Optimized solution
# 入力
a,b=list(map(int,input().split()))

# 初期状態（1口）
n=1

# タップの数
ans=0

# タップを1つずつ差していく
# 差すことでa口増えるが、差した口も1つ減る
while True:
  # b口以上になったら終了
  if n>=b:
    print(ans)
    exit()
    
  n+=a
  n-=1
  ans+=1
# Original solution
A,B=list(map(int,input().split()))
x=0
while (A-1)*x+1<B:
    x+=1
print(x)

# Optimized solution
a, b = list(map(int, input().split()))
print((-(-(b-1)//(a-1))))
# Original solution
import sys
input = sys.stdin.readline

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

end=[[] for i in range(N+2)]

for i in [0]*M:
    l,r,a=list(map(int,input().split()))
    end[r+1].append((l,a))

#Starry Sky tree
seg_el=1<<18#Segment treeの台の要素数

SEG=[0]*(2*seg_el-1)#Segment tree.色々考えると0で初期化してOKそう
ADD=[0]*(2*seg_el-1)#加算用Segment tree,SEG[k]+ADD[k]がkにおける本当の最大値

def updates(a,b,x,k,l,r):#区間[a,b)にxを加算
    
    if a==l and r==b:
        ADD[k]+=x#そのノードのADD値を更新
        return

    if a>=(r+l)//2:
        updates(a,b,x,k*2+2,(l+r)//2,r)#左側の子のみを見る
    elif b<=(r+l)//2:
        updates(a,b,x,k*2+1,l,(l+r)//2)#右側の子のみを見る
    else:
        updates(a,(l+r)//2,x,k*2+1,l,(l+r)//2)#それ以外のときは,SEG[k*2+1]とSEG[k*2+2]で場合分け
        updates((l+r)//2,b,x,k*2+2,(l+r)//2,r)

    SEG[k]=max(SEG[k*2+1]+ADD[k*2+1],SEG[k*2+2]+ADD[k*2+2])

def update_solo(n,x,seg_el):#A[n]=xに更新（反映）
    i=n+seg_el-1
    SEG[i]=x
    i=(i-1)//2
    
    while i>=0:
        SEG[i]=max(SEG[i*2+1]+ADD[i*2+1],SEG[i*2+2]+ADD[i*2+2])
        i=(i-1)//2

for i in range(1,N+2):

    for b,x in end[i]:
        updates(b,i,x,0,0,seg_el)#点数がもらえる区間から出たときにその分を加算

    update_solo(i,SEG[0],seg_el)#[0,i)の最大値はSEG[0](=SEG[0]+ADD[0])と一致するはず

print((SEG[0]))

# Optimized solution
import sys
input = sys.stdin.readline

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

end=[[] for i in range(N+2)]

for i in [0]*M:
    l,r,a=list(map(int,input().split()))
    end[r+1].append((l,a))

#Starry Sky tree
seg_el=1<<18#Segment treeの台の要素数

SEG=[0]*(2*seg_el-1)#Segment tree.色々考えると0で初期化してOKそう
ADD=[0]*(2*seg_el-1)#加算用Segment tree,SEG[k]+ADD[k]がkにおける本当の最大値
seg_el_list=[524286, 262142, 131070, 65534, 32766, 16382, 8190, 4094, 2046, 1022, 510, 254, 126, 62, 30, 14, 6, 2, 0]

def update(k):#SEGのkより上のノードを更新（反映）
    while k>=0:
        k=(k-1)//2
        if SEG[k]==max(SEG[k*2+1]+ADD[k*2+1],SEG[k*2+2]+ADD[k*2+2]):
            break
        SEG[k]=max(SEG[k*2+1]+ADD[k*2+1],SEG[k*2+2]+ADD[k*2+2])

def to_seg(a):#aが終点となる区間をSegment treeの座標へ変換  
    b=(a&(-a)).bit_length()
    return seg_el_list[b]+a//(1<<(b-1))

def add(a,b,x):#区間(a,b]にxを加算
    #print(a,b,x)
    while b!=0:
        ADD[to_seg(b)]+=x
        update(to_seg(b))
        b-=(b&(-b))

    while a!=0:
        ADD[to_seg(a)]+=-x
        update(to_seg(a))
        a-=(a&(-a))
    
for i in range(N+2):
    for b,k in end[i]:
        add(b,i,k)#点数がもらえる区間から出たときにその分を加算

    SEG[i+seg_el-1]=SEG[0]
    update(i+seg_el-1)

print((SEG[0]))
# Original solution
a,b=list(map(int,input().split()));print(('Yay!' if max(a,b)<=8 else ':('))

# Optimized solution
print(('Yay!'if max(list(map(int,input().split())))<9 else':('))
# Original solution
print((["Yay!", ":(", ":("][sum([int(x) > 8 for x in input().split()])]))


# Optimized solution
a, b = [int(x) for x in input().split()]
print((["Yay!", ":("][a > 8 or b > 8]))
# Original solution
A, B = list(map(int, input().split()))

if all([A < 9, B < 9]):
    print("Yay!")
else:
    print(":(")


# Optimized solution
A, B = list(map(int, input().split()))

if A > 8 or B > 8:
    print(":(")
else:
    print("Yay!")
# Original solution
import sys

tmp = [int(i) for i in input().split()]

a = tmp[0]
b = tmp[1]

if a <= 8 and b <= 8:
    print('Yay!')
    sys.stdout.flush()
else:
    print(':(')

# Optimized solution
import sys

tmp = [int(i) for i in input().split()]

a = tmp[0]
b = tmp[1]

if a <= 8 and b <= 8:
    print('Yay!')
    sys.stdout.flush()
else:
    print(':(')
    sys.stdout.flush()
# Original solution
print(([':(','Yay!'][eval('max('+input().replace(' ',',')+')')<=8]))

# Optimized solution
a,b=list(map(int,input().split()))
print(([':(','Yay!'][a<9 and b<9]))