Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		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 {
				fmt.Println(i+1)
				continue
			}
		}
		fmt.Println("NA")
	}
}

C++: #include <iostream>

using namespace std;

int main(){
	int m,n,l,f,sum,ans;
	while(cin>>l){
	if(l==0)break;
	sum=0;
	ans=-1;
	for(int i=1;i<=12;i++){
	cin>>m>>n;
	sum+=m-n;
	if(l<=sum&&ans==-1)ans=i;
	}
	if(ans==-1)cout<<"NA"<<endl;
	else cout<<ans<<endl;
}
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
int L;
main(){
  while(1){
    scanf("%d",&L);
    if(!L) break;
    int sum=0;
    int res=-1;
    for(int i=1;i<13;i++){
      int M,N;
      scanf("%d %d",&M,&N);
      sum+=(M-N);
      if(sum>=L && res==-1) res=i;
    }
    if(res==-1) puts("NA");
    else printf("%d\n",res);
  }
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main() {
	int L;

	while(cin >> L, L) {
		vvi money(12, vi(2));
		REP(i, 12) {
			cin >> money[i][0] >> money[i][1];
		}
		int sum = 0;
		REP(i, 12) {
			sum += money[i][0]-money[i][1];
			if(sum >= L) {
				cout << i+1 << endl;
				break;
			}
		}

		if(sum < L) {
			cout << "NA" << endl;
		}
	}

	return 0;
}

C++: #include <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int L,M,N;
	int kari;
	int meter;
	int i;
	int data;

	while (cin >> L) {
		if (L == 0) {
			break;
		}
		meter = 0;
		for (i = 0; i < 12; i++) {
			cin >> M >> N;
			kari = M - N;
			L -= kari;
			if (L <= 0 && meter == 0) {
				meter = 1;
				data = i+1;
			}
		}

		if (meter == 1) {
			cout << data << endl;
		} else {
			cout << "NA" << endl;
		}
	}
	return 0;

}

C++: int main(void){
	int L,M,N,k[12],i,kai;

	while(0==0){
		scanf("%d\n",&L);
		if(L==0) break;

		kai=0;

		for(i=1;i<13;i++){
			scanf("%d %d\n",&M,&N);
			k[i]=M-N;
		}

        for(i=1;i<1;i++){
			L-=k[i];
			  if(L<=0){
				  kai=i;
				  break;
			  }
		}

		if(kai==0) printf("NA\n");
	    else printf("%d\n",kai);
	}
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int l,m,n;
    int k[12];
    while(cin >> l){
        if(l=0)
            break;
        for(int i=0;i<12;i++){
            cin >> m >> n;
            k[i]=m-n;
        }
        for(int i=0;i<12;i++){
            l -= k[i];
            if(l<=0){
                cout << i+1 << endl;
                break;
            }
        }
        if(l>=0)
            cout << "NA" << endl;
    }
}

C++: #include <iostream>

using namespace std;

int main(void){
	int l,m[12],n[12];
	
	while(cin>>l&&l){
		
		for(int i=0;i<12;i++) cin >> m[i] >> n[i];
		for(int i=0;i<12;i++){
			l -= m[i]-n[i];
			if(l <- 0){
				cout << i+1 << endl;
				break;
			}
		}
		if(l > 0) cout << "NA" << endl;
	}
}

C++: #include <iostream>

using namespace std;

int main()
{
	int l, m, n;
	
	while (cin >> l, l){
		int ct = 0;
		for (int i = 0; i < 12; i++){
			cin >> m >> n;
			if (l > 0){
				l -= (m - n);
				ct++;
			}
		}
		if (ct >= 12){
			cout  << "NA";
		}
		else {
			cout << ct;
		}
		cout << endl;
	}
	return (0);
}

C++: #include <iostream>

int main() {
	int l;
	std::cin >> l;
	while (l != 0) {
		int num = 0;
		for (int m, n, i = 1; i < 13; ++i) {
			std::cin >> m >> n;
			l -= m - n;
			if (l <= 0 && num == 0) {
				num = i;
			}
		}
		if (num == 0) {
			std::cout << "NA\n";
		}
		else {
			std::cout << num << "\n";
		}
		std::cin >> l;
	}
	return 0;
}

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

bool solve() {
  int L;
  cin >> L;
  if (!L) {
    return false;
  }
  int s = 0;
  int ans = -1;
  for (int i = 1; i <= 12; ++i) {
    int m, n;
    cin >> m >> n;
    if (ans != -1) {
      continue;
    }
    s += m - n;
    if (s >= L) {
      ans = i;
    }
  }
  if (ans > 0) {
    cout << ans << endl;
  } else {
    cout << "NA" << endl;
  }
  return true;
}

int main() {
  while (solve()) {}
  return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    int n;
    while(cin>>n&&n){
        int sum=0; int hoge=INF;bool s=true;
        rep(i,12){pii p; cin>>p.first>>p.second;sum+=p.first-p.second;if(sum>n&&s){hoge=i+1;s=false;}}
        if(hoge==INF){cout<<"NA"<<endl;}else cout<<hoge<<endl;
    }
    return 0;
}

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

int main(void){
	int l,m,n;

	while(cin>>l && l){
		int ans,sum = 0;
		bool flg = true;

		for(int i=0;i<12;i++){
			cin>>m>>n;
			sum += m - n;

			if(flg && sum >= l){
				flg = false;
				ans = i + 1;
			}
		}

		if(flg){
			cout<<"NA\n";
		}
		else{
			cout<<ans<<endl;
		}
	}

	return 0;
}

C++: #include<iostream>

using namespace std;
int main()
{
	int l;
	while (cin >> l&&l) {
		int m[12] = {};
		int n[12] = {};
		int cho = 0;
		int tuki = 0;
		for (int i = 0; i < 12;i++) {
			cin >> m[i] >> n[i];
		}
		for (int i = 0; i < 12; i++) {
			cho += m[i] - n[i];
			if (cho >= l) {
				tuki = i+1;
				break;
			}
		}
		if (tuki == 0) {
			cout << "NA" << endl;
		}
		else {
			cout << tuki << endl;
		}
	}

	return 0;
	
}

C++: #include<iostream>
using namespace std;
int main(){
  int i,hess,bell=0;
  long long int m,n,money=0;
  while(1){
    cin >> money;
    if(money==0){
      break;
    }
    for(i=1;i<=12;i++){
      cin >> m >> n;
      money-=m-n;
      if(money<=0 && bell==0){
	bell++;
	hess=i;
      }
    }
    if(bell!=0){
      cout << hess << endl;
      bell=0;
    }
    else{
      cout << "NA" << endl;
    }
  }
  return (0);
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(void)
{
	int cost,saving;
	vector< vector<int> > money(12,2);
	while(1){
		cin >> cost;
		if(cost==0) break;
		saving=0;
		for(int i=0;i<12;i++){
			cin >> money[i][0] >> money[i][1];
		}
		for(int i=0;i<12;i++){
			saving+=(money[i][0]-money[i][1]);
			if(cost<=saving){
				cout << i+1 << endl;
				break;
			}
		}
		if(saving<cost) cout << "NA" << endl;
		money.clear();
	}
	return 0;
}