Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		val := 0
		L, _ := strconv.Atoi(scanner.Text())
		if L == 0 {
			break
		}
		for i := 0; i < 12; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			M, _ := strconv.Atoi(buf[0])
			N, _ := strconv.Atoi(buf[1])
			L -= (M-N)
			if L <= 0 && val == 0 {
				val = i+1
			}
		}
		if val == 0 {
			fmt.Println("NA")
		} else {
			fmt.Println(val)
		}
	}
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 27;
const double EPS = 1e-10;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

int main(){
	int l;
	while(cin >> l && l){
		int m = -1;
		int a, b;
		rep(i, 12){
			cin >> a >> b;
			l -= (a - b);
			if(m == -1 && l < 0){
				m = i;
			}
		}
		if(m >= 0) cout << m + 1 << endl;
		else cout << "NA" << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int L;
  int m,n;
  while(1){
    int sum=0;
    int mon;
    int flag=0;
    cin>>L;
    if(L==0) break;
    
    for(int i=0;i<12;i++){
      cin>>m>>n;
      sum=sum+(m-n);
      if(sum>=L && flag==0){
	mon=i+1;
	flag=1;
      }
    }
    if(sum>=L){
      cout<<mon<<endl;
    }else{
      cout<<"NA"<<endl;
    }
  }
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,j,sum,m,n,nn,x;
	while(1) {
		scanf("%d",&nn);
		if(nn==0) break;
		sum=0;
		x=1;
		for(i=1;i<=12;i++) {
			scanf("%d %d",&m,&n);
			sum+=m-n;
			if(sum<nn) x++;	
		}
		if(sum>=nn) printf("%d\n",x);
		if(sum<nn) printf("NA\n");
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int w,n,z,x,i,k,c;
	while(1){
	c=0;
	k=0;
		scanf("%d",&n);
		 if(n==0) break;
	for(i=0;i<12;i++){
			scanf("%d %d",&z,&x);
			k+=z-x;	
			c++;
		if(k>n) break;				
	}
	if(c==0||c>=12){
		printf("NA\n");
	}
	else{
		printf("%d\n",c);
	}
  }	
	return	0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n;
  while(true){
    cin >> n;
    if(n==0)
      break;
    int tsk = 0, ss=0;
    bool dd = true;
    for(int i=0; i<12; i++){
      int a, b;
      cin >> a >> b;
      tsk += (a-b);
      if(tsk >= n && dd){
	ss = i+1; dd = false;
      }
    }
    if(ss == 0)
      cout << "NA\n";
    else
      cout << ss << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstdlib>
using namespace std;

int main(){
	int l;
	while(scanf("%d",&l)==1,l){
		int m,n,sum=0,month=-1;
		for(int x=0;x<12;++x){
			scanf("%d %d",&m,&n);
			sum += m-n;
			if(sum>=l && month==-1)month=x+1;
		}
		if(month==-1)cout<<"NA"<<endl;
		else cout<<month<<endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    int L;

    while (cin >> L, L) {
        int M, N;
        int ans = 0;

        for (int i = 0; i < 12; i++) {
            cin >> M >> N;
            L -= (M - N);
            if (L <= 0 && ans == 0) 
                ans = i + 1;
        }
        if (ans == 0)
            cout << "NA" << endl;
        else
            cout << ans << endl;
    }

    return 0;
}

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

int main(){
	unsigned long l,m,n;
	unsigned long sum,month;
	bool flag = false;
	
	while(cin >> l,l){
		flag = false;
		month = 0;
		sum = 0;
		for(int i=0;i<12;i++){
			cin >> m >> n;
			sum += (m-n);
			if(sum >= l && flag == false){
				month = i + 1;
				flag = true;
			}
		}
		
		if(!month)	cout << "NA" << endl;
		else	cout << month << endl;
	}
	return 0;
}

C++: #include<iostream>

using namespace std;
int main(void){

	int L,M,N,wa=0,mo=-1;

	cin>>L;
	for(int i=1;i<=12;i++){
		cin>>M>>N;
		wa+=M-N;
		if(wa>=L&&mo==-1) mo=i;
	}
	if(mo!=-1) cout<<mo<<endl;
	else cout<<"NA"<<endl;
	return 0;
}

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

int l;
typedef pair<int,int> pii;
vector<pii> data;
void init(){
  data.clear();
}


bool input(){
  if(!(cin>>l))return false;
  if(l==0)return false;
  for(int i=0;i<12;i++){
    int m,n;
    cin>>m>>n;
    data.push_back(pii(m,n));
  }
  return true;
}

int  solve(){
  int m=0;
  for(int i=0;i<data.size();i++){
    m+=max(0,data[i].first-data[i].second);
    if(!(m<l)){
      return i+1;
    }
  }
  return -1;
}

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

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

int main()
{
	int L,M,N;
	while(scanf("%d", &L), L)
	{
		bool end=false;
		int tot=0;
		for(int i=0; i<12; i++)
		{
			scanf("%d%d", &M,&N);
			if(tot>=L) continue;
			
			tot+=M-N;
			if(tot>=L) printf("%d\n", i+1);
		}
		
		if(tot<L) puts("NA");
	}
}

C++: #include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <string> 
#include <sstream>  
#include <vector> 
#include <time.h>
#include <algorithm>
using namespace std;

int main(){
    int P;
    while(cin >> P){
        if(P == 0)break;
        int Money  = 0,answer = 0;
        int M,N;
        for(int i = 1;12 >= i;i++){cin >> M >> N;Money += M - N;if(Money >= P and answer == 0){answer = i;}}
        if(answer == 0){
            cout << "NA" << endl;
        }else{
            cout << answer << endl;
        }
    }
}

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

int main(){
  int L,M,N;

  while(cin >> L){
    if(L==0) break;
    int count=0, money=0;
    bool flag = false;
    while(1){
      cin >> M >> N;
      count++;
      if(count > 12){
	if(flag == false) cout << "NA" << endl;
	break;
      }
      if(flag == true) continue;
      money += M - N;
      if(L <= money){
	cout << count << endl;
	flag = true;
	continue;
      }
    }    
  }
  return 0;
}

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

int main() {
	int L;
	int i,kozu[12],use[12],sum=0,fl=0,mon;
	while(1){
		cin >> L;
		if(L==0) break;
		for(i=0;i<12;i++){
			cin >> kozu[i] >> use[i];
			sum+=kozu[i]-use[i];
			if(sum>L && fl==0){
				mon=i+1;
				fl=1;
			}
		}
		if(fl==1){
			cout << mon << endl;
		}else{
			cout << "NA" << endl;
		}
		sum=0;
		fl=0;
	}
	return 0;
}

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

int main() {
    int L;
    while (cin >> L, L) {
        vector<int> M(12), N(12);
        for (int i=0; i<12; ++i) {
            cin >> M[i] >> N[i];
        }
        int month = -1, sum = 0;
        for (int i=0; i<12; ++i) {
            sum = sum + M[i] - N[i];
            if (L <= sum) {
                month = i+1;
                break;
            }
        }
        if (month < 0) {
            cout << "NA" << endl;
        } else {
            cout << month << endl;
        }
    }
    return 0;
}