Input:
n,m=list(map(int,input().split()))

c=[0]*(n+2)

for i in range(m):

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

  c[l-1]+=1

  c[r]-=1

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

  c[i]=c[i]+c[i-1]

ans=0

for i in range(n+2):

  if c[i]==m:

    ans+=1

print(ans)

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

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

for i in range(m-1):

  tl,tr=list(map(int,input().split()))

  if l<tl:

    l=tl

  if tr<r:

    r=tr

print((max(r-l+1,0)))

n, m = list(map(int, input().split()))
c = [0] * (n + 2)
for i in range(m):
    l, r = list(map(int, input().split()))
    c[l - 1] += 1
    c[r] -= 1
for i in range(1, n + 2):
    c[i] = c[i] + c[i - 1]
ans = 0
for i in range(n + 2):
    if c[i] == m:
        ans += 1
print(ans)

n, m = list(map(int, input().split()))
l, r = list(map(int, input().split()))
for i in range(m - 1):
    tl, tr = list(map(int, input().split()))
    if l < tl:
        l = tl
    if tr < r:
        r = tr
print((max(r - l + 1, 0)))

-    l, r = list(map(int, input().split()))

+    tl, tr = list(map(int, input().split()))


Input:
n,m=list(map(int,input().split()))

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

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

l=list([0])

for i in range(1,n+1):

  b[i]=b[i-1]+a[i-1]

for i in range(1,n+1):

  l.append(b[i]%m)

d=list()

l.sort()

t,c=0,1

for i in range(1,n+1):

  if l[i]==l[i-1]:

    c+=1

  else:

    if c!=1:

      t += c*(c-1)//2

      c=1

if c!=1:

  t += c*(c-1)//2

print(t)

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

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

l=list([0])

b=0

for i in range(0,n):

  b += a[i]

  l.append(b%m)

l.append(m)

l.sort()

t,c=0,1

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

  if l[i]==l[i-1]:

    c+=1

  else:

    if c!=1:

      t += c*(c-1)//2

      c=1

print(t)

n, m = list(map(int, input().split()))
a = [int(x) for x in input().split()]
b = [0 for x in range(n + 1)]
l = list([0])
for i in range(1, n + 1):
    b[i] = b[i - 1] + a[i - 1]
for i in range(1, n + 1):
    l.append(b[i] % m)
d = list()
l.sort()
t, c = 0, 1
for i in range(1, n + 1):
    if l[i] == l[i - 1]:
        c += 1
    else:
        if c != 1:
            t += c * (c - 1) // 2
            c = 1
if c != 1:
    t += c * (c - 1) // 2
print(t)

n, m = list(map(int, input().split()))
a = [int(x) for x in input().split()]
l = list([0])
b = 0
for i in range(0, n):
    b += a[i]
    l.append(b % m)
l.append(m)
l.sort()
t, c = 0, 1
for i in range(1, n + 2):
    if l[i] == l[i - 1]:
        c += 1
    else:
        if c != 1:
            t += c * (c - 1) // 2
            c = 1
print(t)

-b = [0 for x in range(n + 1)]
-for i in range(1, n + 1):
-    b[i] = b[i - 1] + a[i - 1]
-for i in range(1, n + 1):
-    l.append(b[i] % m)
-d = list()
+b = 0
+for i in range(0, n):
+    b += a[i]
+    l.append(b % m)
+l.append(m)
-for i in range(1, n + 1):
+for i in range(1, n + 2):
-if c != 1:
-    t += c * (c - 1) // 2


Input:
import copy

n=int(input())

org_set=set([i for i in range(1,10**5)])

edges=[]

relations={}

nodes=[]

for i in range(n-1):

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

    edges.append([a,b])

    relations.setdefault(a,[]).append(b)

    nodes.append([])

nodes.append([])

nodes.append([])

max_color=0

for start in range(1,n+1):

    targets=relations.get(start,[])

    color=1

    for target in targets:

        if color in nodes[start]:

            color+=1

        else:

            pass

        nodes[target].append(color)

        if color>=max_color:

            max_color=color

        color+=1

print(max_color)

for edge in edges:

    print((nodes[edge[1]][0]))

n=int(input())

edges=[]

relations={}

nodes=[0,0]

for i in range(n-1):

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

    edges.append([a,b])

    relations.setdefault(a,[]).append(b)

    nodes.append(0)

max_color=0

for start in range(1,n+1):

    targets=relations.get(start,[])

    color=1

    for target in targets:

        if color == nodes[start]:

            color+=1

        else:

            pass

        nodes[target]=color

        if color>=max_color:

            max_color=color

        color+=1

print(max_color)

for edge in edges:

    print((nodes[edge[1]]))

import copy

n = int(input())
org_set = set([i for i in range(1, 10**5)])
edges = []
relations = {}
nodes = []
for i in range(n - 1):
    a, b = list(map(int, input().split(" ")))
    edges.append([a, b])
    relations.setdefault(a, []).append(b)
    nodes.append([])
nodes.append([])
nodes.append([])
max_color = 0
for start in range(1, n + 1):
    targets = relations.get(start, [])
    color = 1
    for target in targets:
        if color in nodes[start]:
            color += 1
        else:
            pass
        nodes[target].append(color)
        if color >= max_color:
            max_color = color
        color += 1
print(max_color)
for edge in edges:
    print((nodes[edge[1]][0]))

n = int(input())
edges = []
relations = {}
nodes = [0, 0]
for i in range(n - 1):
    a, b = list(map(int, input().split(" ")))
    edges.append([a, b])
    relations.setdefault(a, []).append(b)
    nodes.append(0)
max_color = 0
for start in range(1, n + 1):
    targets = relations.get(start, [])
    color = 1
    for target in targets:
        if color == nodes[start]:
            color += 1
        else:
            pass
        nodes[target] = color
        if color >= max_color:
            max_color = color
        color += 1
print(max_color)
for edge in edges:
    print((nodes[edge[1]]))

-org_set = set([i for i in range(1, 10**5)])


Input:
n=int(input())

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

k=[]

ans=0

for i in range(400005):

  k.append(0)

for i in range(n):

  if i-a[i]>=0:

    ans+=k[i-a[i]]

  if a[i]+i<400005:

    k[a[i]+i]+=1

print(ans)

n=int(input())

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

thing={}

ans=0

for i in range(n):

  if i-a[i] in thing:

    ans+=thing[i-a[i]]

  if i+a[i] in thing:

    thing[i+a[i]]+=1

  else:

    thing[i+a[i]]=1

print(ans)

n = int(input())
a = list(map(int, input().split()))
k = []
ans = 0
for i in range(400005):
    k.append(0)
for i in range(n):
    if i - a[i] >= 0:
        ans += k[i - a[i]]
    if a[i] + i < 400005:
        k[a[i] + i] += 1
print(ans)

n = int(input())
a = list(map(int, input().split()))
thing = {}
ans = 0
for i in range(n):
    if i - a[i] in thing:
        ans += thing[i - a[i]]
    if i + a[i] in thing:
        thing[i + a[i]] += 1
    else:
        thing[i + a[i]] = 1
print(ans)

-k = []
+thing = {}
-for i in range(400005):
-    k.append(0)
-    if i - a[i] >= 0:
-        ans += k[i - a[i]]
-    if a[i] + i < 400005:
-        k[a[i] + i] += 1
+    if i - a[i] in thing:
+        ans += thing[i - a[i]]
+    if i + a[i] in thing:
+        thing[i + a[i]] += 1
+    else:
+        thing[i + a[i]] = 1


Input:
import sys

import os

import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())

il = lambda: list(map(int, sys.stdin.buffer.readline().split()))

iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()

isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

def main():

    if os.getenv("LOCAL"):

        sys.stdin = open("input.txt", "r")

    N = ii()

    ret = float('inf')

    I = int(math.sqrt(N)) * 10

    for i in range(1, I):

        if N%i == 0:

            j = N//i

            ret = min(ret, j + i - 2)

    print(ret)

if __name__ == '__main__':

    main()

import sys

import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())

il = lambda: list(map(int, sys.stdin.buffer.readline().split()))

iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()

isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

def main():

    if os.getenv("LOCAL"):

        sys.stdin = open("input.txt", "r")

    N = ii()

    m = int(N ** .5)

    while N % m != 0:

        m -= 1

    else:

        print((int(N / m + m - 2)))

if __name__ == '__main__':

    main()

import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")
    N = ii()
    ret = float("inf")
    I = int(math.sqrt(N)) * 10
    for i in range(1, I):
        if N % i == 0:
            j = N // i
            ret = min(ret, j + i - 2)
    print(ret)

if __name__ == "__main__":
    main()

import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]
iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")
    N = ii()
    m = int(N**0.5)
    while N % m != 0:
        m -= 1
    else:
        print((int(N / m + m - 2)))

if __name__ == "__main__":
    main()

-import math
-    ret = float("inf")
-    I = int(math.sqrt(N)) * 10
-    for i in range(1, I):
-        if N % i == 0:
-            j = N // i
-            ret = min(ret, j + i - 2)
-    print(ret)
+    m = int(N**0.5)
+    while N % m != 0:
+        m -= 1
+    else:
+        print((int(N / m + m - 2)))