Problem:


勉強を開始した時刻と終了した時刻の情報を基に、1日で勉強した時間の合計が t 以上であるかをチェックし、達していない場合は足りない時間を求めるプログラムを作成します。時間は1時間を1単位とし、分や秒は考えないものとします。時刻は24時間表記で1時間単位で表します。

1日の勉強の目標時間と、実際に勉強した時間の情報（勉強の回数 n、それぞれの勉強の開始時刻 s と終了時刻 f）を入力とし、勉強時間の合計が目標に達しているかを調べ、達していれば "OK" を、達していない場合は足りない時間を出力するプログラムを作成してください。ただし、それぞれ行った勉強時間は重複しません。

例：

目標時間
勉強した時間
判定

10時間
 6時〜11時 ＝ 5時間

12時〜15時 ＝ 3時間

18時〜22時 ＝ 4時間
OK

14時間
6時〜11時 ＝ 5時間

13時〜20時 ＝ 7時間

2時間不足

入力

複数のデータセットの並びが与えられます。入力の終わりはゼロひとつの行で示されます。各データセットは以下の形式で与えられます。

t
n
s1 f1
s2 f2
:
sn fn

１行目に１日の目標時間 t (0 ≤ t ≤ 22)、 ２行目に勉強の回数 n (1 ≤ n ≤ 10)が与えられます。続く n 行に i 回目の勉強の開始時刻 si と終了時刻 f (6 ≤ si, fi ≤ 22) が与えられます。

データセットの数は 100 を超えません。

出力

データセットごとに、OK または足りない時間を１行に出力します。

入力例

10
3
6 11
12 15
18 22
14
2
6 11
13 20
0

出力例

OK
2



Sample input:
10
3
6 11
12 15
18 22
14
2
6 11
13 20
0


Sample output:
OK
2

Submission status: Wrong Answer

Solution code:
t=int(input())
n=int(input())
b=0
for i in range(n):
    s,f=map(int,input().split())
    a=f-s
    b+=a
if t<=b:
    print("OK")
else:
    print(t-b)

Submission status: Accepted

Solution code:
while 1:
    t = int(input())
    if t == 0:break
    n = int(input())
    x = 0
    for i in range(n):
        x += (lambda lst:lst[-1] - lst[0])(list(map(int,input().split())))
    print('OK' if t<=x else (t-x))

Submission status: Accepted

Solution code:
while 1:
    t = int(input())
    if t == 0:break
    t -= sum(map(lambda lst:lst[-1] - lst[0],[ list(map(int,input().split())) for i in range(int(input())) ]))
    print('OK' if t<=0 else t)

Submission status: Accepted

Solution code:
import sys
f = sys.stdin


while True:
    t = int(f.readline())
    if t == 0:
        break
    n = int(f.readline())
    sf = (map(int, f.readline().split()) for _ in range(n))
    
    rest = t - sum(f - s for s, f in sf)
    print('OK' if rest <= 0 else rest)

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0: break
    t = 0
    for i in range(int(raw_input())):
        t += reduce(lambda x, y: y-x, map(int, raw_input().split()))
    else:
        if n <= t:
            print 'OK'
        else:
            print n-t

Submission status: Accepted

Solution code:
while True:
    n = int(raw_input())
    if n == 0: break
    t = 0
    for i in range(int(raw_input())):
        t += reduce(lambda x, y: y-x, map(int, raw_input().split()))
    else:
        print 'OK' if n <= t else n-t

Submission status: Accepted

Solution code:
while True:
    t = input()
    if t == 0:
        break
    studied = 0
    n = input()
    for i in range(n):
        s = raw_input().split(" ")
        f_s = int(s[1]) - int(s[0])
        studied += f_s
    if studied >= t:
        print "OK"
    else:
        print "%d" % (t - studied)

Submission status: Accepted

Solution code:
while 1:
    a=int(input())
    if a == 0: break
    b=int(input())
    d=0
    for _ in range(b):
        c=list(map(int,input().split()))
        d+=c[1]-c[0]
    print(a-d if a>d else 'OK')

Submission status: Accepted

Solution code:
while 1:
    a=int(input())
    if a == 0: break
    b=int(input())
    for _ in range(b):
        c=list(map(int,input().split()))
        a-=c[1]-c[0]
    print(a if a>0 else 'OK')

Submission status: Accepted

Solution code:
while True:
    t= int(input())
    if t== 0: break
    n= int(input())
    c= [list(map(int, input().split())) for _ in range(n)]
    sf= sum(c[i][1]-c[i][0] for i in range(n))
    print("OK" if t<= sf else t-sf)

Submission status: Accepted

Solution code:
# Aizu Problem 0238: Time to Study

import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


while True:
    T = int(input())
    if T == 0:
        break
    n = int(input())
    for _ in range(n):
        start, end = [int(_) for _ in input().split()]
        T -= (end - start)
    print("OK" if T <= 0 else T)

Submission status: Accepted

Solution code:
while True:
    t=int(input())
    if t == 0:
        break
    n=int(input())
    b=0
    for i in range(n):
        s,f=map(int,input().split())
        a=f-s
        b+=a
    if t<=b:
        print("OK")
    else:
        print(t-b)

Submission status: Accepted

Solution code:
# AOJ 0238 Time to Study
# Python3 2018.6.25 bal4u

while 1:
	t = int(input())
	if t == 0: break
	n = int(input())
	sm = 0
	for i in range(n):
		s, f = map(int, input().split())
		sm += f-s
	print("OK" if sm >= t else t - sm)

Submission status: Accepted

Solution code:
while 1:
    t = int(input())
    if t == 0:break
    n = int(input())
    s = 0
    for _ in range(n):
        a, b = map(int, input().split())
        s += b - a
    print("OK" if s >= t else t - s)

Submission status: Accepted

Solution code:
while True:
  t = int(input())
  if t == 0:
    break
  n = int(input())
  acc = 0
  for _ in range(n):
    s, f = map(int, input().split())
    acc += f - s
  if acc >= t:
    print("OK")
  else:
    print(t - acc)

Submission status: Accepted

Solution code:
while True:
  s= 0
  a = int(input())
  if a == 0:
    break
  else:
    n = int(input())
    for y in range(n):
      b = map(int,raw_input().split())
      c,v = b[0],b[1]
      s += v-c
    if s >= a :
      print "OK"
    else:
      print a-s

Submission status: Accepted

Solution code:
import sys
while True:
	t = input()
	if t == 0: sys.exit(0)
	t -= sum(map(lambda x: x[1] - x[0], [map(int, raw_input().split()) for i in xrange(input())]))
	if t <= 0: print "OK"
	else: print t

Submission status: Accepted

Solution code:
while True:
    t=input()
    if t==0:break
    n=input()
    sumt=0
    for i in range(n):
        s,f=map(int,raw_input().split())
        sumt+=f-s
    print "OK" if sumt>=t else t-sumt

Submission status: Accepted

Solution code:
if __name__ == '__main__':


    while True:

        sign = int(raw_input())
        if sign == 0:
            break

        num = int(raw_input())

        time = 0
        for i in xrange(num):

            a,b = map(int, raw_input().split(' '))
            time += b - a

        jug = sign - time
#        print 'jug,sign,time'
#        print jug,sign,time
        if jug <= 0:
            print 'OK'

        else:
            print jug

Submission status: Accepted

Solution code:
while 1:
    t = input()
    if t==0: break
    n = input(); S = 0;
    for i in xrange(n):
        s,f = map(int,raw_input().split())
        S += f-s
    print "OK" if S>=t else t-S

Submission status: Accepted

Solution code:
while 1:
	t=int(raw_input())
	if t==0:break
	n=int(raw_input())
	for i in range(n):
		s,f=map(int, raw_input().split())
		t -= f-s
	print t if t > 0 else "OK"

Submission status: Accepted

Solution code:
import sys,os
while 1:
    t = int(input())
    if t == 0: break
    n = int(input())
    sf = [list(map(int, input().split())) for _ in range(n)]
    
    time = 0
    for i in sf:
        start,end = i
        if start > end:
            time += end - (start-24)
        else:
            time += end - start
    if time >= t:
        print("OK")
    else:
        print(t-time)

Submission status: Accepted

Solution code:
while 1:
    t = int(input())
    if t == 0:
        break
    n = int(input())
    T = 0
    for i in range(n):
        s,f = map(int,input().split())
        T += f - s

    if T >= t:
        print("OK")
    else:
        print(t-T)

Submission status: Accepted

Solution code:
#標準入力をし0だった場合はループを抜ける
while True:
    num = int(input())
    if num == 0:break
    else:
        num1 = int(input())
        kei = 0
        
        #勉強時間の合計を計算する
        for _ in range(num1):
            a,b = map(int,input().split())
            kei += b - a
            
        #勉強時間が足りてたら"OK"足りてなかったら足りない時間を出力する
        if num <= kei:print("OK")
        else:print(num - kei)

Submission status: Accepted

Solution code:
while True:
    a = int(input())
    if a == 0:
        break
    b = int(input())
    for i in range(b):
        c,d = map(int,input().split())
        a -= d-c
    if a <= 0:
        print("OK")
    else:
        print(a)

Submission status: Accepted

Solution code:
while True:
    try:
        t=int(input())
        n=int(input())
        M=0
        for i in range(n):
            s,f=map(int,input().split())
            A=f-s
            M=M+A
        if t>M:
            print(t-M)
        else:
            print("OK")
    except:
        break

Submission status: Accepted

Solution code:
while True:
    t = int(input())
    if t==0:
        break
    n = int(input())
    hour = 0
    for i in range(n):
        s,f = map(int,input().split())
        hour += (f-s)
        
    if hour >= t:
        print("OK")
    else:
        print(t-hour)

Submission status: Accepted

Solution code:
while True:
  t = int(input())
  if t == 0:
    break
    
  n = int(input())
  
  ans = 0
  for _ in range(n):
    s, f = map(int, input().split())
    ans += f - s
    
  if ans >= t:
    print('OK')
  else:
    print(t - ans)

Submission status: Accepted

Solution code:
while True:
  t=int(input())
  if t == 0: break
  n = int(input())
  for i in range(n):
    s,f=map(int,input().split())
    t-=f-s
  if t<1:
    print("OK")
  else:
    print(t)

Submission status: Accepted

Solution code:
while 1:
    t = int(input())
    if t == 0: break
    n = int(input())
    i = 0
    sum = 0
    while i < n:
        s, f = map(int, input().split())
        a = f - s
        sum = sum + a
        i += 1
    if sum < t:
        print(t - sum)
    else:
        print("OK")

Submission status: Accepted

Solution code:
# AOJ 0238 Time to Study
# Python3 2018.6.25 bal4u
 
while 1:
    t = int(input())
    if t == 0: break
    n = int(input())
    sm = 0
    for i in range(n):
        s, f = map(int, input().split())
        sm += f-s
    print("OK" if sm >= t else t - sm)

Submission status: Accepted

Solution code:
while 1:
    t = int(input())
    if t == 0:
        break
  
    n = int(input())
  
    ans = 0
    for _ in range(n):
        s, f = map(int, input().split())
        ans += f - s
  
    if ans >= t:
        print("OK")
    else:
        print(t - ans)

Submission status: Accepted

Solution code:
while 1:
    t = int(input())
    if t == 0:
        break
 
    n = int(input())
 
    ans = 0
    for _ in range(n):
        s, f = map(int, input().split())
        ans += f - s
 
    if ans >= t:
        print("OK")
    else:
        print(t - ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Time to Study
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0238

"""
import sys


def solve(t):
    n = int(input())
    for _ in range(n):
        s, f = map(int, input().split())
        t -= (f-s)
    return 'OK' if t <= 0 else t


def main(args):
    while True:
        t = int(input())
        if t == 0:
            break
        ans = solve(t)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
while 1:
    a=int(input())
    if a == 0: break
    b=int(input())
    for _ in range(b):
        c=list(map(int,input().split()))
        a-=c[1]-c[0]
    print(a if a>0 else 'OK')

Submission status: Accepted

Solution code:
while True:
  t=int(input())
  if t==0:
    break
  n=int(input())
  c=0
  for i in range(n):
    a,b=map(int,input().split())
    c+=(b-a)
  if t<=c:
    print("OK")
  else:
    print(t-c)

Submission status: Accepted

Solution code:
while 1:
    t=int(input())
    if t==0:break
    n=int(input())
    for i in range(n):
        s,f=map(int,input().split())
        t-=f-s
    if t<1:print("OK")
    else:print(t)

Submission status: Accepted

Solution code:
while 1:
    t = int(input())
    if t == 0:
        break

    n = int(input())

    ans = 0
    for _ in range(n):
        s, f = map(int, input().split())
        ans += f - s

    if ans >= t:
        print("OK")
    else:
        print(t - ans)

Submission status: Runtime Error

Solution code:
while 1:
    t = int(input())
    if t == 0:break
    n = int(input())
    x = 0
    for i in range(n):
        x += (lambda lst:lst[-1] - lst[0])(list(map(int,input().split())))
    print('OK' if t<=x else (t-x))
while 1:
    t = int(input())
    if t == 0:break
    #n = int(input())
    #x = 0
    #for i in range(n):
    t -= sum(map(lambda lst:lst[-1] - lst[0],[ list(map(int,input().split())) for i in range(int(input())) ]))
    print('OK' if t<=0 else t)

Submission status: Runtime Error

Solution code:
while True:
    t=int(input())
    n=int(input())
    b=0
    if t == 0:
        break
    for i in range(n):
        s,f=map(int,input().split())
        a=f-s
        b+=a
    if t<=b:
        print("OK")
    else:
        print(t-b)