Harryxun/stf_run huggingface dataset:
A, B, C, D, E, F = map(int, input().split())
W = set()
S = set()
wtr = 100*A
sgr = 0

i = 1
j = 0
while(wtr <= F):
  while(wtr <= F):
    W.add(wtr)
    wtr = i*A*100 + j*B*100
    j +=1
  i +=1
  j = 0
  wtr = i*A*100 + j*B*100
  
i = 0
j = 0
while(sgr <= F):
  while(sgr <= F):
    S.add(sgr)
    sgr = i*C + j*D
    j +=1
  i +=1
  j = 0
  sgr = i*C + j*D
answtr = 100*A
anssgr = 0
  
for wtr in sorted(list(W), reversed):
  for sgr in sorted(list(S), reversed):
    if (sgr*(answtr+anssgr) > anssgr*(wtr+sgr)) and (sgr*(100+E)<=E*(wtr+sgr) and (wtr+sgr<=F)):
      answtr = wtr
      anssgr = sgr
      if anssgr*(100+E)==E*(answtr+anssgr):
        print("{} {}".format(answtr+anssgr, anssgr))
        exit()
print("{} {}".format(answtr+anssgr, anssgr))

### FIXED CODE ###

A, B, C, D, E, F = map(int, input().split())
W = set()
S = set()
wtr = 100*A
sgr = 0

i = 1
j = 0
while(wtr <= F):
  while(wtr <= F):
    W.add(wtr)
    wtr = i*A*100 + j*B*100
    j +=1
  i +=1
  j = 0
  wtr = i*A*100 + j*B*100
  
i = 0
j = 0
while(sgr <= F):
  while(sgr <= F):
    S.add(sgr)
    sgr = i*C + j*D
    j +=1
  i +=1
  j = 0
  sgr = i*C + j*D
answtr = 100*A
anssgr = 0
  
for wtr in W:
  for sgr in S:
    if (sgr*(answtr+anssgr) > anssgr*(wtr+sgr)) and (sgr*(100+E)<=E*(wtr+sgr) and (wtr+sgr<=F)):
      answtr = wtr
      anssgr = sgr
print("{} {}".format(answtr+anssgr, anssgr))
N = int (input ())
S = str (input ())

def dot_num ():
    cnt = 0
    for i in range (1, N+1):
        if S [i] == '.':
            cnt += 1
    return cnt

def hash_num ():
    cnt = 0
    for i in range (1, N+1):
        if S [i] == '#':
            cnt += 1
    return cnt

dots = dot_num ()
hashes = hash_num ()

if S [0] == '.':
    dots -= 1

if S [N] == '#':
    hashes -= 1
    
print (min (dots, hashes))


### FIXED CODE ###

N = int (input ())
S = str (input ())
S = '.' + S
N += 1
cnt = 0
inf = int(1e9)

A = list(range(N))
for i in range(N):
    A[i] =[inf,inf]
A[0][0] = A[0][1] = 0
for i in range (1,N):
    for j in range (2):
        if j == 1:
            if S[i] == '.':
                A[i][j] = min(A[i][j], A[i-1][0] + 1)
                A[i][j] = min(A[i][j], A[i-1][1] + 1)
            else:
                A[i][j] = min(A[i][j], A[i-1][0] )
                A[i][j] = min(A[i][j], A[i-1][1] )
        else:
            if S[i] == '#':
                A[i][j] = min(A[i][j], A[i-1][0] + 1)
            else:
                A[i][j] = min(A[i][j], A[i-1][0])                

ans = min(A[N-1][0],A[N-1][1])

print (ans)
def main():
    n,m=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in [0]*m]
    g=[[] for _ in [0]*n]
    [g[a-1].append(b-1) for a,b in ab]
    [g[b-1].append(a-1) for a,b in ab]
    ans=[None]*n
    ans[0]=0
    temp=[0]
    while temp:
        i=temp.pop()
        for j in g[i]:
            if ans[j]==None:
                ans[j]=ans[i]^True
                temp.append(j)
            else:
                if ans[i]^ans[j]==0:
                    #print(n*(n-1)//2-m)
                    print(1/0)
                    return 0
    print((ans.count(0)*(ans.count(0)-1)//2)*(ans.count(1)*(ans.count(1)-1)//2)-m)
main()

### FIXED CODE ###

def main():
    n,m=map(int,input().split())
    ab=[list(map(int,input().split())) for _ in [0]*m]
    g=[[] for _ in [0]*n]
    [g[a-1].append(b-1) for a,b in ab]
    [g[b-1].append(a-1) for a,b in ab]
    ans=[None]*n
    ans[0]=0
    temp=[0]
    while temp:
        i=temp.pop()
        for j in g[i]:
            if ans[j]==None:
                ans[j]=ans[i]^True
                temp.append(j)
            else:
                if ans[i]^ans[j]==0:
                    print(n*(n-1)//2-m)
                    return 0
    print(ans.count(0)*ans.count(1)-m)
main()
def how_many_times_divisible(n):
	ans = 0
	while n % 2 == 0:
		n /= 2
		ans += 1
	return ans
 
n = int(raw_input())
a = map(int, raw_input().split())
ans = min(map(how_many_times_divisible, a))
 
print ans

### FIXED CODE ###

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

cou = []
for i in range(N):
    cc = 0
    while True:
        if x[i] % 2 == 0:
            x[i] /= 2
            cc+=1
        else:
            cou.append(cc) 
            break   
print(min(cou))
n = int(input())
l = list(map(int, input().split()))

sum = 0
for i in range(n):
    sum += l[i]

print(sum(l))


### FIXED CODE ###

#
# 4d
#


def main():
    n = int(input())
    a = list(map(int, input().split()))
    print(f"{min(a)} {max(a)} {sum(a)}")


if __name__ == '__main__':
    main()
import sys
input = sys.stdin.readline

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

time = 0
A_num = 0
B_num = 0
A_len = len(A_list)
B_len = len(B_list)
while (time <= K) and (A_num != A_len or B_num != B_len):
    if A_num >= A_len:
        B = B_list[B_num]
        time += B
        B_num += 1

    elif B_num >= B_len:
        A = A_list[A_num]
        time += A
        A_num += 1
    else:
        A = A_list[A_num]
        B = B_list[B_num]
        if A < B:
            time += A
            A_num += 1

        elif A > B:
            time += B
            B_num += 1

        else:
            add = 1
            time += A
            while (A_list[A_num + add] == B_list[B_num + add]) and \
                  (time < K):
                time += A_list[A_num + add]
                add += 1
            if A_list[A_num + add] < B_list[B_num + add]:
                A_num += add
            else:
                B_num += add
print(A_num + B_num)

### FIXED CODE ###


import sys
import numpy as np
input = sys.stdin.readline

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


A_list.insert(0, 0)
B_list.insert(0, 0)
A_cumsum = np.cumsum(A_list)
B_cumsum = np.cumsum(B_list)

time = B_cumsum[-1]
ans, j = 0, M



for i in range(N+1):
    if A_cumsum[i] > K:
        break
    while B_cumsum[j] > K - A_cumsum[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)
# -*- coding: utf-8 -*-

import sys


def main():
    n, q = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]

    tree = {}
    data = [0 for x in range(n)]

    for _ in range(n - 1):
        a, b = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
        if a not in tree:
            tree[a] = []
        tree[a].append(b)

    for _ in range(q):
        p, x = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
        data[p - 1] += x

    def add(p, x):
        data[p - 1] += x
        if p not in tree:
            return
        for p2 in tree[p]:
            add(p2, data[p - 1])

    add(1, 0)

    print(" ".join([str(x) for x in data]))


if __name__ == "__main__":
    main()


### FIXED CODE ###

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

import sys


sys.setrecursionlimit(10**6)


def main():
    n, q = map(int, sys.stdin.readline().split())

    tree = [[] for x in range(n + 1)]
    data = [0 for x in range(n + 1)]

    for _ in range(n - 1):
        a, b = map(int, sys.stdin.readline().split())
        tree[a].append(b)
        tree[b].append(a)

    for _ in range(q):
        p, x = map(int, sys.stdin.readline().split())
        data[p] += x

    def dfs(p, p2, x):
        data[p] += x
        for p3 in tree[p]:
            if p3 == p2:
                continue
            dfs(p3, p, data[p])

    dfs(1, 0, 0)

    print(" ".join([str(x) for x in data[1:]]))


if __name__ == "__main__":
    main()
from collections import deque

def bfs():
    d = [[float("inf") for i in range(W)] for j in range(H)]
    dx = [1,-1,0,0]
    dy = [0,0,1,-1]
    que = deque([])
    que.append((0,0))
    d[0][0] = 0
    while que:
        p = que.popleft()
        if p[0] == W-1 and p[1] == H-1:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0<=nx<W and 0<=ny<H and maze[ny][nx] != "#" and d[ny][nx] == float("inf"):
                que.append((nx,ny))
                d[ny][nx] = d[p[1]][p[0]] + 1
    return d[H-1][W-1]

H,W = map(int,input().split())
maze = [list(input()) for i in range(H)]

cnt = 1

for i in range(H):
    cnt += maze[i].count("#")

if d[H-1][W-1] == float("inf"):
    print(-1)
else:
    print(H*W-bfs()-cnt)


### FIXED CODE ###

from collections import deque

def bfs():
    d = [[float("inf") for i in range(W)] for j in range(H)]
    dx = [1,-1,0,0]
    dy = [0,0,1,-1]
    que = deque([])
    que.append((0,0))
    d[0][0] = 0
    while que:
        p = que.popleft()
        if p[0] == W-1 and p[1] == H-1:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0<=nx<W and 0<=ny<H and maze[ny][nx] != "#" and d[ny][nx] == float("inf"):
                que.append((nx,ny))
                d[ny][nx] = d[p[1]][p[0]] + 1
    return d[H-1][W-1]

H,W = map(int,input().split())
maze = [list(input()) for i in range(H)]

cnt = 1

for i in range(H):
    cnt += maze[i].count("#")

if bfs() == float("inf"):
    print(-1)
else:
    print(H*W-bfs()-cnt)
N,L = map(int,input().split())
s =[]
for i in range(N):
    s.append(input())
s.sort()
result = ''.join(s)
print(result)

### FIXED CODE ###

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

arr = [A, B, C]
fives = 0
sevens = 0

for num in arr:
    if num == 5:
        fives += 1
    if num == 7:
        sevens += 1

if fives == 2 and sevens == 1:
    print("YES")
else:
    print("NO")
N, R = map(int, input().split())
def a(N,R):
     if N >= 10:
             print(R)
     else:
             print(R+(100*(10-N)))
     return
  
a()

### FIXED CODE ###

N, R = map(int, input().split())
def a(N,R):
     if N >= 10:
             print(R)
     else:
             print(R+(100*(10-N)))
     return
  
a(N,R)
N,K = map(int,input().split())
S_list = ['0'] + list(input()) + ['-1']

s_count_list =[]

cnt = 1
for i in range(1,N+2) :
    if S_list[i] == S_list[i-1] :
        cnt +=1
    else:
        s_count_list.append(cnt)
        cnt = 1
if S_list[1] == '0':
    s_count_list[0] = s_count_list[0] -1
else:
    s_count_list.pop(0)

ruisekiwa = [0]
for i,s in enumerate(s_count_list):
    ruisekiwa.append(s_count_list[i] + s)

for i in range(0,len(ruisekiwa),2):
    left = i
    right = min((i + (2 * K) + 1),len(ruisekiwa))
    tmp = ruisekiwa[right] - ruisekiwa[left]
    answer = max(tmp,answer)

print(answer)

### FIXED CODE ###

q, k = list(map(int, input().split()))
list = [int(i) for i in input()]

# 0 ,1 のまとまりを作る
sum01 = []
pre = 1
cnt = 0
# 111010
# 001010
for i, e in enumerate(list):
    if e != pre:
        sum01.append(cnt)
        cnt = 1
        pre = e
    else:
        cnt += 1
if cnt != 0:
    sum01.append(cnt)

if len(sum01) % 2 == 1:
    sum01.append(0)

# print(sum01)
Add = 2 * k + 1
ruiseki = [0]
for i, e in enumerate(sum01):
    ruiseki.append(ruiseki[i] + sum01[i])

# print(ruiseki)
answer = 0
for i in range(0, len(sum01), 2):
    left = i
    right = min(i + Add, len(sum01))
    temp = ruiseki[right] - ruiseki[left]
    answer = max(temp, answer)

print(answer)
n=int(input())
z=0
for i in range(n):
  a,b=input().split()
  if b=="BTC":
    z += a*380000
  else:
    z += a
print(z)

### FIXED CODE ###

n=int(input())
z=0
for i in range(n):
  a,b=input().split()
  if b=="BTC":
    z += float(a)*380000
  else:
    z += int(a)
print(z)
import math
n = int(input())

print(2 * n // math.gcd(2, n))


### FIXED CODE ###


import math
n = int(input())

if n % 2 == 0:
    n = n // 2

print(2 * n)
n,k=map(int,input().split())
l=[]
sa=[]
ans=[]
for i in range(n):
    h=int(input())
    l.append(h)
for i in range(1,n):
    sa.append(l[i]-[i-1])
sa.sort()
sa.reverse()
for i in range(k-1):
    ans.append(sa[i])
print(min(ans))

### FIXED CODE ###

n,k=map(int,input().split())
l=[]
sa=[]
for i in range(n):
    h=int(input())
    l.append(h)
l.sort()
for i in range(n-k+1):
    sa.append(l[i+k-1]-l[i])
print(min(sa))
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

li_f = list.sort(F)
li_a = list.sort(A, reverse=True)

combined1 = [x * y for (x, y) in zip(li1, li2)]

for i in range(K + 1):
  n_max = combined1.index(max(combined1))
  li_a[n_max] = li_a[n_max] - (i - (i - 1))

print(max(combined1))

### FIXED CODE ###

import numpy as np

import sys
input = sys.stdin.buffer.readline

N, K = map(int, input().split())
A = np.array(input().split(), np.int64)
F = np.array(input().split(), np.int64)

A.sort()
F.sort()

F= F[::-1]

left = -1
right = (A * F).sum()
while left + 1 < right:
  middle = (left + right) // 2
  right_arr = np.maximum(0, A - middle // F).sum() <= K
  if right_arr:
    right = middle
  else:
    left = middle
print(right)
import math
N, D=map(int, input().split())
print(math.ceil(N/(2*D+1))

### FIXED CODE ###

import math
N, D =map(int, input().split())
print(math.ceil(N/(2*D+1)))
A, B = cin()

def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

def sieve(N):
    p = 0
    prime = []
    is_prime = [1 for _ in range(N + 1)]
    is_prime[0], is_prime[1] = 0, 0
    for i in range(2, N + 1):
        if is_prime[i]:
            p += 1
            temp = i
            prime.append(i)
            while(temp <= N):
                is_prime[temp] = 0
                temp += i
            is_prime[i] = 1
    return prime

s = sieve(int(min(A, B) ** 0.5) + 1)
s.append(1)
ans = 0
for i in s:
    if A % i == 0 and B % i == 0:
        ans += 1
print(ans)

### FIXED CODE ###

import collections

def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:  f += 2
    if n != 1:  a.append(n)
    return a

A, B = cin()
A, B = min(A, B), max(A, B)
res = collections.Counter(prime_factorize(A))
keys = list(res.keys())
keys.append(1)
ans = 0
for i in keys:
    if B % i == 0:
        ans += 1
print(ans)
n = int(input())
temp = input()
h = temp.split()

for i,item in enumerate(h):
    h[i] = int(item)

dp = []
def rec_flog(i):
    print(dp)
    if len(dp) > i:
        return dp[i]
    elif i >= 2:
        step1 = abs(h[i] - h[i - 1]) + rec_flog(i-1)
        step2 = abs(h[i] - h[i -2]) + rec_flog(i-2)
        dp.append(step1 if step1 <= step2 else step2)
        return dp[i]
    else :
        dp.append(h[1])
        return h[1]


print(rec_flog(6))




### FIXED CODE ###


n = int(input())
temp = input()
h = temp.split()
for i,item in enumerate(h):
    h[i] = int(item)
dp = [0]
for i,height in enumerate(h):
    if i >=2:
        step1 = dp[i - 1] + abs(height - h[i-1])
        step2 = dp[i-2] + abs(height - h[i-2])
        dp.append(step1 if step1 <= step2 else step2)
    elif i == 1:
        dp.append(abs(height - h[i-1]))

print(dp.pop())
n = int(input())
a = list(map(int, input().split()))
t = [a.count(i) for i in range(n)]
for i in range(n//2):
  if t[i*2+n%2] != 0 or t[i*2+1+n%2] != 2: or t[0] > 1:
    print(0)
    exit()
print(2**(n//2))

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
d = dict()
mod = 10**9 + 7
for i in l:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1
d2 = dict()
for i in range(1+n%2,n,2):
  d2[i] = 2
if n%2:
  d2[0] = 1
if d == d2:
  print(2**(n//2)%mod)
else:
  print(0)
a,b = input().split()
a = int(a)
b = int(b*100)
p = (a*b)//100
print(p)

### FIXED CODE ###

a,b = input().split()
a = int(a)
b = round(float(b)*100)
p = (a*b)//100
print(p)
n=input()
s=0
a=[105,135,165,195,189]
for i in a:
  if n>=i:
    s+=1
print(s)

### FIXED CODE ###

n=int(input())
s=0
a=[105,135,165,195,189]
for i in a:
 if n>=i:
  s+=1
print(s)
n = int(input())
march = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(n):
    str = input()
    if str[0] in march:
        march[str[0]] += 1

for i in list(march):
    if march[i] == 0:
        march.pop(i)

c = 0
if len(march) == 3:
    tmpc = 1
    for chr in march:
        tmpc *= march[chr]
    c += tmpc
elif len(march) == 4:
    for i in march:
        tmpm = march.copy()
        tmpm.pop(i)
        tmpc = 1
        for chr in tmpm:
            tmpc *= tmpm[chr]
        c += tmpc
elif len(march) == 5:
    for i in march:
        tmpm1 = march.copy()
        tmpm1.pop(i)
        for j in tmpm1:
            tmpm2 = tmpm1.copy()
            tmpm2.pop(j)
            tmpc = 1
            for chr in tmpm:
                tmpc *= tmpm[chr]
            c += tmpc
print(c)

### FIXED CODE ###

n = int(input())
march = {'M':0, 'A':0, 'R':0, 'C':0, 'H':0}
for i in range(n):
    str = input()
    if str[0] in march:
        march[str[0]] += 1
for i in list(march):
    if march[i] == 0:
        march.pop(i)
c = 0
if len(march) == 3:
    tmpc = 1
    for chr in march:
        tmpc *= march[chr]
    c += tmpc
elif len(march) == 4:
    for i in march:
        tmpm = march.copy()
        tmpm.pop(i)
        tmpc = 1
        for chr in tmpm:
            tmpc *= tmpm[chr]
        c += tmpc
elif len(march) == 5:
    keys = list(march.keys())
    for i in range(len(keys)):
        for j in range(i + 1, len(keys)):
            tmpm = march.copy()
            tmpm.pop(keys[i])
            tmpm.pop(keys[j])
            tmpc = 1
            for chr in tmpm:
                tmpc *= tmpm[chr]
            c += tmpc
print(c)
r = input()
r = int(r)
pi = 3.14159265
print("{0:6f} {1:6f}".format((r ** 2 * pi), (2 * r * pi)))

### FIXED CODE ###

r = input()
r = float(r)
pi = 3.14159265358979
print("{0:10f} {1:10f}".format((r ** 2 * pi), (2 * r * pi)))
p = [1] * 1000001
for i in range(2, 1001):
    if p[i] == 0:
        continue
    for j in range(2, 1000000/i+1):
        p[i*j] = 0

t = int(raw_input())
for i in range(t):
    n = int(raw_input())
    res = n * (n-1) / 2 + 2
    for j in range(2, n+1):
        if p[j] == 1:
            res -= (n / j - 1) * (j - 1)
    print res

### FIXED CODE ###

count = range(1000001) 
for i in xrange(2, 500001):
    for n in xrange(i*2, 1000001, i):
        count[n] -= (count[i] - 1) 
 
count[1] = 2
for i in xrange(2, 1000001):
    count[i] += count[i-1]

t = int(raw_input())
for i in xrange(t):
    n = int(raw_input())
    print count[n] - n + 1
S = input()
if S == 'abc':
    return 'Yes'
elif S == 'acb':
    return 'Yes'
elif S == 'acb':
    return 'Yes'
elif S == 'bac':
    return 'Yes'
elif S == 'bca':
    return 'Yes'
elif S == 'cab':
    return 'Yes'
elif S == 'cba':
    return 'Yes'
else:
    return 'NO'

### FIXED CODE ###

S = input()
if S == 'abc':
    print('Yes')
elif S == 'acb':
    print('Yes')
elif S == 'acb':
    print('Yes')
elif S == 'bac':
    print('Yes')
elif S == 'bca':
    print('Yes')
elif S == 'cab':
    print('Yes')
elif S == 'cba':
    print('Yes')
else:
    print('No')
N = int(input())
ans = 1
A=[]
for i in rage(N): 
    A.append(input())

for i in range(1, N):
    if A[i-1][-1] == A[i][0]:
        ans *= 1
    else:
        ans *= 0    
    
if all(A.count(i) == 1 for i in A):
    ans *= 1
else:
    ans *= 0  

### FIXED CODE ###

N = int(input())
ans = 1
A=[]
for i in range(N): 
    A.append(input())

for i in range(1, N):
    if A[i-1][-1] == A[i][0]:
        ans *= 1
    else:
        ans *= 0    
    
if all(A.count(i) == 1 for i in A):
    ans *= 1
else:
    ans *= 0  
    
print("Yes" if ans == 1 else "No")
a=int(input())
b=int(input())
c=int(input())
x=int(input())
x=int(x/50)
countlist=[]

for e in range(a+1):
    if x < e*10:
        break
    else:
        x -= e*10
        count=0
        for f in range(b+1):
            if x < f*2 :
                break
            else:
                x-=2*f
                count=0
                for g in range(c+1):
                	if x<g:
                      break
                    else:
                     	count = count +1
				countlist.append(count)

print(sum(countlist))
                
 




### FIXED CODE ###

#define
a=int(input())
b=int(input())
c=int(input())
x=int(input())

count=0
countlist=[]
#sorting
for e in range(0,a+1):
    if e*500 <= x:
        y=x-e*500
        for f in range(0,b+1):
            if f*100 <= y:
                z=y-100*f
                for g in range(0,c+1):
                    if g*50 == z :                                            
                        count = count +1

print(count)
height,width=map(int,input().split())
graph = [[s for s in input()] for i in range(height)]

for r in range(width):
    for c in range(height):
        if graph[r][c]==".":
            continue

        if r>0 and graph[r-1][c]=="#":
            continue

        if r<width-1 and graph[r+1][c]=="#":
            continue

        if c>0 and graph[r][c-1]=="#":
            continue

        if c<height-1 and graph[r][c+1]=="#":
            continue

        print("No")
        exit()
print("Yes")

### FIXED CODE ###

height,width=map(int,input().split())
graph = [[s for s in input()] for i in range(height)]

for r in range(height):
    for c in range(width):
        if graph[r][c]==".":
            continue

        if r>0 and graph[r-1][c]=="#":
            continue

        if r<width-1 and graph[r+1][c]=="#":
            continue

        if c>0 and graph[r][c-1]=="#":
            continue

        if c<height-1 and graph[r][c+1]=="#":
            continue

        print("No")
        exit()
print("Yes")
n,m = [int(i) for i in input().split()]

n_left = 1
n_right = n
result = 0

for i in range(m):
    l_i,r_i = [int(i) for i in input().split()]
    if(l_i > n_left):
        n_left = l_i
    if(r_i < n_right):
        n_right = r_i
    if(n_left > n_right):
        print(0)
        sys.exit(0)

print(n_right - n_left + 1)

### FIXED CODE ###

n,m = [int(i) for i in input().split()]

n_left = 1
n_right = n
result = 0

for i in range(m):
    l_i,r_i = [int(i) for i in input().split()]
    if(l_i > n_left):
        n_left = l_i
    if(r_i < n_right):
        n_right = r_i

if(n_left > n_right):
    print(0)
else:
    print(n_right - n_left + 1)