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++: //2013/06/17    パソコン甲子園２０１１[1]
#include<iostream>
using namespace std;

int main()
{

        int t;
        int n;
        int s,f;

        while(true){
                int sum=0;
                cin >> t ;
                if(t==0)
                        break;
                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<iostream>
using namespace std;
int main()
{
	int t,n,s[10],f[10],sum = 0;
	while(1){
		sum = 0;
		cin >> t;
		if(t==0)break;
		cin >> n;
		for(int i=0 ; i<n ; ++i){
			cin >> s[i] >> f[i];
			sum += f[i] - s[i];
		}
		if(sum>=t){
			cout << "OK\n";
		}else{
			cout << t-sum << endl;
		}
	}
	return 0;
}

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

int main(){
	int sum;
	int a,b;
	int m,n;
	while(cin>>m,m!=0){
		cin>>n;
		sum=0;
		for(int i=0;i<n;i++){
			cin>>a>>b;
			sum+=b-a;
		}
		if(m<sum)cout<<"OK"<<endl;A
		else cout<<m-sum<<endl;
	}
}

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

C++: #include <stdio.h>

int main() {
	for (;;) {
		int t, n;

		scanf("%d", &t);

		if (t == 0)
			return 0;

		scanf("%d", &n);

		for (int i = 0; i < n; i++) {
			int j, k;
			scanf("%d", &j);
			scanf("%d", &k);
			t -= k - j;
		}

		if (t <= 0)
			printf("OK\n");
		else
			printf("%d\n", t);
	}
	
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	while(true){
		
		int t;
		
		cin >> t;
		
		if(t == 0){
			break;
		}
		
		int n;
		
		cin >> n;
		
		for(int i = 0; i < n; i++){
			int num1, num2;
			cin >> num1 >> num2;
			t -= (num2 - num1);
		}
		
		if(t > 0){
			cout << t << endl;
		}else{
			cout << "OK" << endl;
		}
		
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
    int i,a,b,c,d,e;
	while(1){
	scanf("%d",&a);
	if(a==0) break;
	scanf("%d",&b);
	e=0;
	for(i=0;i<b;i++){
	scanf("%d %d",&c,&d);
	e+=d-c;
	}
	if(a<=e){
	printf("OK\n");
	}
	else if(a>e){
	printf("%d\n",a-e);
	}
	}
	return 0;
	}

C++: #include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
	while (true) {
		int t, n, s, f;
		int sum = 0;
		
		cin >> t;
		if (t == 0) break;

		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<iostream>
using namespace std;

int ans[100];
int cor;

int main(){
	int T,N;
	int s,t,sum;
	while( cin >> T >> N )
	{
		sum = 0;
		for(int i = 0;i < N;i++){
			cin >> s >> t;
			sum += t-s;
		}
		if( sum < T )
			ans[cor] = T-sum;
		cor++;
	}
	for(int i = 0;i < cor;i++){
		if( ans[i] )
			cout << ans[cor] << endl;
		else
			cout << "OK" << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int t,n,s,f;
  
  while(1){
    cin>>t;
    if(t==0)break;
    cin>>n;
    int sum=0;
    for(int i=0;i<n;i++){
      cin>>s>>f;
      sum+=f-s;
    }
    
    if(sum>=t)cout<<"OK\n";
    else cout<<t-sum<<"\n";
  }
  
  return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int t,n,s,f,i,z;
	scanf("%d",&t);
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			scanf("%d %d",&s,&f);
			z+=f-s;
		}
			if(z>=10){
				printf("OK\n");
			}
			else{
				printf("2\n");
			}
		scanf("%d",&n);
	}
	return 0;
}

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

int main(void)
{
	int s,n,a,b;

	while(cin >> s, s){
		cin >> n;
		int now = 0;
		while(--n, n >= 0){
			cin >> a >> b;
			now += (b - a);
		}
		if(now >= s)
			cout << "OK";
		else
			cout << s-now;
		cout << endl;
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
    // Your code here!
    int d,n,s,t,sum;
    int main(void){
        while(cin>>d>>n,d){
            sum=0;
            for(int i=0; i<n; i++){
                cin>>s>>t;
                sum+=t-s;
            }
            if(sum<d)cout<<d-sum<<endl;
            else cout<<"OK"<<endl;
        }
    }

C++: #include<iostream>
using namespace std;
int n, m, a, b, sum;
int main() {
	while (true) {
		cin >> n;
		if (!n) { break; }
		cin >> m; sum = 0;
		for (int i = 0; i < m; i++) {
			cin >> a >> b;
			sum += b - a;
		}
		if (sum >= n) { cout << "OK" << endl; }
		else { cout << n - sum << endl; }
	}
}

C++: #include<stdio.h>
int main(void)
{
    int a,b,c[15],d[15],i,f;
	scanf("%d",&a);
	while(a!=0){
	    f=0;
	    scanf("%d",&b);
	    for(i=0;i<b;i++){
		    scanf("%d %d",&c[i],&d[i]);
		}
		for(i=0;i<b;i++){
		    f=f+(d[i]-c[i]);
		}
		if(f>=a) printf("OK\n");
		else if(f<a) printf("%d\n",a-f);
		scanf("%d",&a);
	}
	return 0;
}

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

int main(){
	int t,n,s,f,a[20],i;
	while(cin>>t){
		if(t==0)break;
		cin>>n;
	for(i=0;i<n;i++){
		cin>>s>>f;
		a[i]=f-s;	
	}a[n]=0;
	for(i=0;i<n;i++){
		a[i+1]=a[i]+a[i+1];
	}if(a[n]>=t){
		cout<<"OK"<<endl;
	}if(a[n]<t){
		t=t-a[n];
		cout<<t<<endl;
	}
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void){
 int t,n,o=0,s=0,f=0;
 while(1){
     o=0;
 cin>>t>>n;
 if(t==0)break;
 for(int i = 0;i<n;i++){
     cin>>s>>f;
   o=o+(f-s);
 }
  if(t<=o){
       cout<<"OK"<<endl;
   }   
    if(t>o){
       cout<<t-o<<endl;
   }  
 } 
}

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

typedef long long ll;

ll gcd( ll x, ll y );
ll lcm( ll x, ll y );

int main()
{
    int t;
    int n;
    int s, f;

    cin >> t;

    while ( t != 0 ) {
        cin >> n;
        int work = 0;
        for ( int i = 0; i < n; ++i ) {
            cin >> s >> f;
            work += f - s;
        }
        if ( t > work ) {
            cout << t - work << endl;
        } else {
            cout << "OK" << endl;
        }
        cin >> t;
    }

    return 0;
}

ll gcd( ll x, ll y )
{
    if ( y == 0 ) return x;
    return gcd( y, x % y );
}

ll lcm( ll x, ll y )
{
    return x / gcd( x, y ) * y;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int T, N, S, A, B;

	while (true)
	{
		cin >> T;

		if (T == 0) { break; }

		cin >> N; S = 0;

		for (int i = 0; i < N; i++)
		{
			cin >> A >> B;

			S += B - A;
		}

		if (S >= T)
		{
			cout << "OK" << endl;
		}
		else
		{
			cout << T - S << endl;
		}
	}

	return 0;
}

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

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

int main() {
	int t;
	while (cin >> t, t) {
		int n;
		cin >> n;

		int sa = 0;
		for (int i = 0;i < n;i++) {
			int s, f;
			cin >> s >> f;
			sa += (f - s);
		}

		if (sa < t)cout << t - sa << endl;
		else cout << "OK" << endl;
	}
	return 0;
}