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

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

C++: #include<iostream>
using namespace std;
int main() {
	int t[111], n, s, f, ans[111], an;
	an = 0;
	while (1) {
		an = an + 1;
		cin >> t[an];
		if (t[an] == 0) {
			an = an - 1;
			goto a;
		}
		cin >> n;
		ans[an] = 0;
		for(int i=1;i<=n;i++){
			cin >> f >> s;
			ans[an] = ans[an] + s-f;
		}
	}
a:;
	for (int i = 1; i <= an; i++) {
		if (ans[i] >= t[i]) {
			cout << "OK" << endl;
		}
		else {
			cout << t[i] -ans[i] << endl;
		}
	}
}

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

int main()
{
    int N;
    int T;
    int startTime, finishTime;
    
    while(cin >> N, N){
        cin >> T;
        for(int i = 0; i < T; i++){
            cin >> startTime >> finishTime;
            N -= finishTime - startTime;
        }
        
        if(N <= 0) std::cout << "OK" << std::endl;
        else cout << N << endl;
        
    }
}

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

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

C++: #include<iostream>
#include<vector>
using namespace std;
int t;
vector<int> n;

void init(){
  t=0;
  n.resize(0);
}

bool input(){
  cin>>t;
  if(t==false)return false;
  int t_n;
  cin>>t_n;
  for(int i=0;i<t_n;i++){
    int a,b;
    cin>>a>>b;
    n.push_back(b-a);
  }
  return true;
}

int solve(){
  int res=t;
  for(int i=0;i<n.size();i++){
    res-=n[i];
  }
  res=max(res,0);
  return res;
}

int main(){
  while(init(),input()){
    int ans=solve();
    if(ans==0){
      cout<<"OK"<<endl;
    }else{
      cout<<ans<<endl;
    }
  }
}

C++: #include <iostream>
using namespace std;
int main(void){
    int t; //１日の目標時間
    int n; // 勉強の回数
    int s[22], f[22]; //毎回の勉強開始時刻と終了時刻

    while(true){
        cin >> t;
        if(t == 0) break;

        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> s[i] >> f[i];
        }
        
        int time = 0; //１日に勉強した合計時間
        for(int i = 0; i < n; i++){
            time += f[i] - s[i];
        }
        if(time >= t) 
            cout << "OK" << endl;
        else{
            cout << t - time << endl;
        }
    }
}

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

C++: #include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    while(1){
        int a;
        cin>>a;
        if(a==0)return 0;
        int total=0;
        int N;
        cin>>N;
        for(int i=0;i<N;i++){
            int A,B;
            cin>>A>>B;
            total+=B-A;
        }
        if(a<=total)puts("OK");
        else cout<<a-total<<endl;
    }
    return 0;
}

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

int main(void)
{
  int t, n, a, b, s;
  while (cin >> t, t)
  {
    cin >> n;
    for (int i = s = 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,z;
	scanf("%d",&t);
	while(t!=0){
	z=0;
	scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d %d",&s,&f);
			z+=f-s;
		}
			if(z>=t){
				printf("OK\n");
			}
			else{
				printf("%d\n",t-z);
			}
		scanf("%d",&t);
	}
	return 0;
}

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

C++: #include<iostream>

int main()
{
	int t, n;
	while( std::cin >> t, t )
	{
		std::cin >> n;
		for( int i = 0; i != n; ++i )
		{
			int s, f;
			std::cin >> s >> f;
			t -= f - s;
		}

		if( t <= 0 )
			std::cout << "OK" << std::endl;
		else
			std::cout << t << std::endl;
	}

	return 0;
}

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

int main()
{
    int t,n,s,f,sum;
    
    while(cin>>t&&t){
        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<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue> 

using namespace std;

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

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

int main()
{
  int t, n, a, b, sub, sum = 0;
  vector<int> s, f;
  
  while(cin >> t, t) {
    cin >> n;
    for (int  i = 0; i < n; i++) {
      cin >> a >> b;
      s.push_back(a);
      f.push_back(b);
    }

    for (int i = 0; i < s.size(); i++) {
      sub = f[i] - s[i];
      sum += sub;
    }

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

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<iostream>
using namespace std;
int main(void)
{
	int t,n,i,j,s,f,sum;
	while(1) {
		cin >> t;
		if(t==0) break;
		cin >> n;
		sum=0;
		for(i=0;i<n;i++) {
			cin >> s >> f;
			sum+=f-s;
		}
		if(sum>=t) cout << "OK" << endl;
		else cout << t-sum << endl;
	}
	exit(0);
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(void)
{
	int t;
	while (cin >> t, t){
		int n, s, f;
		int stime = 0;
		cin >> n;
		while (n--){
			cin >> s >> f;
			stime += (f - s);
		}
		if (t <= stime){
			cout << "OK" << endl;
		}
		else {
			cout << t - stime << endl;
		}
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int main (){
       int a;
       while(cin>>a){
            if(a==0)break;
            int N;
            cin>>N;
            int ans=0;
            for(int i=0;i<N;i++){
                      int c,d;
                      cin>>c>>d;
                       ans=ans+(d-c);
               }
                       if(ans>a){
                              cout<<"OK"<<endl;
                        }
                        else{   cout<<a-ans<<endl;
                      }   
                }
         return 0;
  }