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++: //  0206.cpp
//  2012/09/03.

#if 1

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    int L;
	while(cin >> L && L)
	{
		int ans = 13;
		rep(i, 12)
		{
			int M, N;
			cin >> M >> N;
			
			L -= M - N;
			
			if(L <= 0) chmin(ans, i);
		}
		
		if(ans == 13) cout << "NA" << endl;
		else cout << ans + 1 << endl;
	}
}

#endif

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int i ,j=0 ,n ,m ,L ,tmp[12] ,savings=0;
  while( 1 ){  // 目標金額
    cin >> L;
    if( L == 0 ){
      break;
    }
    for( i=0 ; i<12 ; i++ ){
      tmp[i] = 0;
    }
    if( L == 0 ){
      break;
    }
    
    for( i=1 ; i<=12 ; i++ ){
      cin >> m >> n;       // 小遣い　使用金額
      savings = savings + ( m - n );
      if( savings >= L ){
	tmp[i] = 1;
      }
    }
    
    if( savings >= L ){
      for( i=0 ; i<12 ; i++ ){
	if( tmp[i] == 1 ){
	  cout << i << endl;
	  break;
	}
      }
    }
    
    else{
      cout << "NA" << endl;
    }
    savings = 0;
    j = 0;

  }

  return 0;
}

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

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

C++: #include <iosteam>
#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=0i<12;i++){
			cin >> money[i][0] >> money[i][1];
		}
		for(int i=0;i<12;i++){
			saving+=money[i][0]-[i][1];
			if(cost<=saving){
				cout << i+1 << endl;
				break;
			}
		}
		if(money<saving) cout << "NA" << endl;
		money.clear();
	}
	return 0;
}

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

int money(int n){
	int sum = 0;
	int month = 0;
	int flag = 0;
	for(int i=0; i<12; ++i){
		int a,b;
		cin >> a >> b;
		sum += a-b;
		if(flag == 0){
			if(sum >= n){
				month = i+1;
				flag = 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 <vector>
#include <functional>
#include <algorithm>
using namespace std;

#define rep(i,a) for(int i=0;i<(a);++i)

int main()
{
    int L, M, N, sum;
    while(cin >> L && L) {
        bool ok = false;
        sum = 0;
        rep(i, 12) {
            cin >> M >> N;
            sum += M - N;
            if(!ok && sum >= L) {
                cout << i + 1 << endl;
                ok = true;
            }
        }
        if(!ok) 
            cout << "NA" << endl;
    }
}

C++: #include <iostream>

using namespace std;

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

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

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

using namespace std;

const int MAX_M = 12;

int main() {
	while (true) {
		int L, M, N;
		int info[MAX_M] = {0};

		int temp = 0;

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

		for (int i = 0; i < 12; i++) {
			temp += info[i];
			
			if (temp > L) {
				cout << i+1 << endl;
				break;
			}
		}
		
		if (temp < L) {
			cout << "NA" << endl;
		}
	}
	
	return 0;
}

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

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

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

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

  while(true){
    cin >> l;
    if(!l)break;

    int f = 1;
    for(int i=0;i<12;i++){
      cin >> m >> n;
      l -= m-n;
      if(l<=0 && f){
	cout << i+1 << endl;
	f = 0;
      }
    }
    if(l<=0)cout << "NA" << endl;
  }
  return 0;
}

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

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

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

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

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

int main()
{
  int L, M, N;
  while( cin >> L, L ) {
    bool flag = false;
    for(int i=0; i<12; i++) {
      cin >> M >> N;
      L -= M - N;
      if( L <= 0 && !flag ) {
	cout << i+1 << endl;
	flag = true;
      }
    }

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