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<stdio.h>
int main(void)
{
	int n,t,i,k,h,x,w;
	w=0;
	while(1){
	scanf("%d",&n);
	if(n==0) break;
	scanf("%d",&t);
	for(i=0;i<t;i++){
		scanf("%d %d",&k,&h);
		w+=h-k;
		}
	if(n<w){
		printf("OK\n");
		}
	else{
		x=n-w;
		printf("%d\n",x);
		}
	w=0;	
	}
		return 0;
}

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

using namespace std;

int main(){
    int n, t, a, b;
    while(cin >> t, t){
	cin >> n;
	int sum = 0;
	for(int i = 0;i < n;i++){
	    cin >> a >> b;
	    sum += b - a;
	}
	if(sum >= t){
	    cout << "OK" << endl;
	}
	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;
		else cout<<m-sum<<endl;
	}
}

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

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

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

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

int main()
{
    int t, n, s, f;
    while(cin >> t && t)
    {
        int sum = 0;
        cin >> n;
        REP(n){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;


	while(true){
		int 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 if(sum < t)
			cout << t - sum << endl;

	}
	return 0;
}

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

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

  while(1){
    ans=0;
    cin >> t;
    if(t==0){
      break;
    }
    cin >> n;
    for(int i=0;i<n;i++){
      cin >> s >> f;
      ans+=f-s;
    }
    if(ans>=t){
      cout << "OK\n";
    }else{
      cout << t-ans << '\n';
    }
  }
  
  return 0;
}

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

C++: #include<stdio.h>
int main(void)
{
    int i,a,b,c,d,e;
	e=0;
	while(1){
	scanf("%d",&a);
	if(a==0) break;
		scanf("%d",&b);
	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 <iostream>
using namespace std;

int main(){
    int time,cnt,h_s,h_f,ans;
    while(1){
        ans=0;
        cin >> time;
        if(time == 0){
            break;
        }
        cin >> cnt;
        for(int i=0;i<cnt;i++){
            cin >> h_s >> h_f;
            ans += h_f - h_s;
        }
        if(ans >= time){
            cout << "OK" << endl;
        }
        else{
            cout << time - ans << endl;
        }
    }
}

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 <bits/stdc++.h>
using namespace std;
int main(void) {
    int t,n,s,f;
    while (cin>>t) {
        if (t==0) {
            break;
        } else {
            int 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;
            }
        }
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
    ll t, n;
    while (cin >> t) {
        if (t == 0) break;
        cin >> n;
        ll tmp = 0;
        rep(i, n) {
            ll a, b;
            cin >> a >> b;
            tmp += b-a;
        }
        if (tmp >= t) {
            cout << "OK" << endl;
        } else {
            cout << t-tmp << endl;
        }
    }
}

C++: // 2013/07/12 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int t;
		cin >> t;

		if(t==0)
			break;

		int n;
		cin >> n;

		int sum = 0;

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

			sum += (f-s);
		}

		if(sum>=t){
			cout << "OK" << endl;
		}
		else{
			cout << t-sum << endl;
		}
	}

	return 0;
}

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

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

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

int t, n, sum;

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

	return 0;
}