Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		t, _ := strconv.Atoi(scanner.Text())
		if t == 0 {
			break
		}
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		for i  := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			s, _ := strconv.Atoi(buf[0])
			f, _ := strconv.Atoi(buf[1])
			t -= (f-s)
		}
		if t <= 0 {
			fmt.Println("OK")
		} else {
			fmt.Println(t)
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
    int t;
    while(cin>>t&&t){
        int n,s,f,sum=0;
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>s>>f;
            sum+=f-s;
        }
        if(sum>=t)cout<<"OK"<<endl;
        else cout<<t-sum<<endl;
    }
    return 0;
}

C++: #include <cstdio>
int main() {
	int t,n;
	while(scanf("%d",&t),t) {
		scanf("%d",&n);
		int sum=0;
		for(int i=0;i<n;i++) {
			int s,f;
			scanf("%d %d",&s,&f);
			sum+=(f-s);
		}
		if(sum>=t) printf("OK\n"); else printf("%d\n",t-sum);
	}
}

C++: #include<iostream>
using namespace std;
int main(){
	for(;;){
	   int t;
	   cin>>t;
	   if(t==0)break;
	   int n;
	   cin>>n;
	   int a[n],b[n];
	   for(int i=0;i<n;i++){
		   cin>>a[n]>>b[n];
		   t-=(b[n]-a[n]);
	   }
	   if(t<=0){
		   cout<<"OK"<<endl;
	   }
	   else{
		   cout<<t<<endl;
	   }
	}
	return 0;
}

C++: #include<iostream>
using namespace std;

int main() {
    int t;
    int n;
    int s,f;
    int all=0;
    int temp;
    
    cin >> t;
    cin >> n;
    
    for(int i = 0; i < n; i++) {
        cin >> s;
        cin >> f;
        
        temp = f - s;
        all += temp;
        temp = 0;
    }
    
    if ((t - all) >= 0) {
        cout << (t - all) << "\n";
    }
    else
    {
        cout << "OK" << "\n" ;
    }
    
    return 0;
}

C++: #include<stdio.h>

int main(){
	for(;;){
		int t,n,s,f,m,o=0;
		scanf("%d",&t);
		if(t==0)break;
		scanf("%d",&n);
		for(m=0;m<n;m++){
			scanf("%d%d",&s,&f);
			o+=f-s;
		}
		if(o>=t)printf("OK\n");
		else printf("%d\n",t-o);
	}
	return 0;
}

Python: # 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)

Python: 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)

Python: #標準入力をし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)

Python: 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)

Python: 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)

Python: 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)

Python: 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)

Python: 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)

Python: 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)

Python: 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)

Python: # -*- 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:])

Python: 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)

Python: 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')

Python: 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)

Python: 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))

Python: 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)

Python: 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)

Python: 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')

Python: 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)

Python: 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)

Python: 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)