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++: #include <iostream>
using namespace std;

int money(int n){
	int sum = 0;
	int month = 0;
	for(int i=0; i<12; ++i){
		int a,b;
		cin >> a >> b;
		sum += a-b;
		if(sum >= n){
			month = i+1;
		}
	}
	return month;
}

int main(){
	int n;
	int result;
	while(cin >> n&& n){
		result = money(n);
		if(result == 0){
			cout << "NA" << endl;
		} else {
			cout << result << endl;
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
  int n;
  while (scanf("%d ", &n) == 1) {
    if (n == 0) {
      break;
    }
    int a[12] ,b[12];
    for (int i = 0; i < 12; i++) {
      scanf("%d %d ", a + i, b + i);
    }
    for (int i = 1; i <= 12; i++) {
      int _a, _b;
      _a = a[i - 1], _b = b[i - 1];
	n -= (_a - _b);
	//printf("n = %d\n", n);
      if (n <= 0) {
	cout << i << endl;
	goto next;
      }
    }
    cout << "NA" << endl;
  next:;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int main() {
  while( 1 ) {
    int l;
    cin >> l;
    if( !l ) { return EXIT_SUCCESS; }
    
    int mth = -1;
    for( int i = 1; i <= 12; i++ ) {
      int m, n;
      cin >> m >> n;
      l -= ( m - n );
      if( mth == -1 && l <= 0 ) { mth = i; }
    }
    cout << ( mth == -1 ? "NA" : to_string( mth ) ) << endl;
  }
}

C++: #include <cstdio>
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main()
{
    int m, n, l, s, f, res;
    while (true) {
        scanf("%d", &l); if (l == 0) break;
        s = f = 0;
        rep(i, 12) {
            scanf("%d%d", &m, &n);
            s += (m - n);
            if (!f && s >= l) { res = i+1; f = 1; }
        }
        if (!f) puts("NA"); else printf("%d\n", res);
    }
    return 0;
}

C++: #include<iostream>

int main(){

	int l;
	while (std::cin >> l){

		if (l == 0)break;

		bool flg = true;
		for (int i = 1, m, n; i <= 12; i++){
			std::cin >> m >> n;
			l -= (m - n);

			if (flg&&l <= 0)std::cout << i << std::endl, flg = false;
			if (i == 12 && l > 0)std::cout << "NA" << std::endl;
		}
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
 
int main(void){
  int cost,M,N,cnt,yatta,flg,cnt1;
   
  while(1){
    cnt = yatta = flg = cnt1 = 0;
     
    cin >> cost;
    if( cost == 0 ) break;
 
    while(1){
 
    
      if( cnt1 == 12 ) break;
 
      cin >> M >> N;
 
      if( flg == 0 ){
      yatta += (M - N);
      if( cost <= yatta ) flg = 1;
      cnt++;
      }
      cnt1++;
    }
 
    if( cost <= yatta ) cout << cnt << endl;
    else cout << "NA" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int L;
	while(cin >> L , L){
		int sum = 0 , ans = -1;
		rep(i,12){
			int a,b;
			cin >> a >> b;
			sum += a - b;
			if(!~ans && sum >= L) ans = i+1;
		}
		if(~ans)cout << ans << endl;
		else cout << "NA" << endl;
	}
}

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

using namespace std;

int main() {
	int l, m, n, sum, i;
	bool flag;

	while (cin >> l, l) {
		sum = 0;
		flag = true;
		for (i = 1; i < 13; ++i) {
			cin >> m >> n;
			sum += m - n;
			if (flag && sum >= l) {
				l = i;
				flag = false;
			}
		}
		if (flag) {
			cout << "NA" << endl;
		}
		else {
			cout << l << endl;
		}
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000000;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  int n;
  while(cin >> n && n) {
    int ans=0;
    for(int i=1; i<=12; i++) {
      int a,b;
      cin >> a >> b;
      if(n>0) {
	n-=a-b;
	if(n<=0) ans=i;
      }
    }
    if(ans) pr(ans);
    else pr("NA");
  }
  return 0;
}

C++: // 2011/08/09 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int L;
		cin >> L;
		if(L==0)
			break;

		int M[12], N[12];
		for(int i=0; i<12; i++)
			cin >> M[i] >> N[i];

		int sav = 0;
		bool flg = false;
		for(int i=0; i<12; i++){
			sav += (M[i]-N[i]);
			if(sav>=L){
				cout << i+1 << endl;
				flg = true;
				break;
			}
		}

		if(!flg)
			cout << "NA" << endl;
	}

	return 0;
}

C++: #include <stdio.h>
int main(){
    int n,l,r,tot;
    bool f;
    while(1){
        scanf("%d",&n);
        if(n==0)return 0;
        tot=0;
        f=false;
        for(int i=0;i<12;i++){
            scanf("%d%d",&l,&r);
            tot+=l-r;
            if(tot>=n&&!f){
                f=true;
                printf("%d\n",i+1);
            }
        }
        if(!F)printf("NA\n");
        
    }
}

C++: #include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int main() {
  while( 1 ) {
    int l;
    cin >> l;
    if( !l ) { return EXIT_SUCCESS; }
    
    int mth = -1;
    for( int i = 1; i <= 12; i++ ) {
      int m, n;
      cin >> m >> n;
      l -= ( m - n );
      if( mth == -1 && l < 0 ) { mth = i; }
    }
    cout << ( mth == -1 ? "NA" : to_string( mth ) ) << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>

using namespace std;

int main() {
	int l;
	while (true) {
		cin >> l;
		if (!l) break;
		int flag = 13;
		for (int i = 1; i <= 12; i++) {
			int a, b;
			cin >> a >> b;
			l -= a;
			l += b;
			if (l <= 0 && flag == 13) {
				flag = i;
			}
		}
		if (flag == 13) {
			cout << "NA" << endl;
		} else {
			cout << flag << endl;
		}
	}
	return 0;
}

C++: // 2010/12/21 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int L;
		cin >> L;
		if(L==0)
			break;
		int M[12], N[12];
		for(int i=0; i<12; i++)
			cin >> M[i] >> N[i];

		int chochiku = 0;
		int getsusuu = 0;
		for(int i=0; i<12; i++){
			chochiku += (M[i]-N[i]);
			if(chochiku>=L){
				getsusuu = i+1;
				break;
			}
		}

		if(getsusuu!=0)
			cout << getsusuu << endl;
		else
			cout << "NA" << endl;
	}

    return 0;
}

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

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

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

C++: #include<iostream>
using namespace std;
int main(){
    int L;
    cin >> L;
    int t;
    t = 0;
    for(int i=0;i<12;++i){
        int Plus;
        int Minus;
        cin >> Plus >> Minus;
        t += Plus - Minus
        if (t>=L){
            cout << i+1 << endl;
            break;
        }
        }
        
    if (t<L){
        cout << "NA" << endl;
    }
    return 0;
    }