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)
				break
			}
		}
		fmt.Println("NA")
	}
}

C++: #include<iostream>
int main(){
	while(1){
		int a;
		std::cin>>a;
		if(a==0)break;
		int b,c=0,d;
		for(int i=1;i<13;i++){
			int n,m;
			std::cin>>n>>m;
			b+=n;
			b-=m;
			if(a>=b&&c==0)d=i,c=1;
		}
		if(c==0)std::cout<<"NA"<<std::endl;
		else std::cout<<d<<std::endl;
	}
	return 0;
}

C++: #include<cstdio>
int main()
{
	int l,c=0,t=0,m,n;
	while(1){
		scanf("%d",&l);
		if(l==0)break;
		for(int i=0;i<12;i++){
			scanf("%d %d",&m,&n);
			t+=m-n;
			c++;
			if(t>=l)c--;
		}
		if(t>=l)printf("%d\n",c+1);
		else
			printf("NA\n");
		t=c=0;
	}
	return 0;
}

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

int main(int argc, char *argv[]){
  int n, m, l;
  while(cin >> l, l){
    int sum = 0, month = 13;
    for (int i = 0; i < 12; i++) {
      cin >> n >> m;
      sum += n - m;
      if(sum >= l && month > i){
        month = i + 1;
      }
    }
    if(month <= 12){
      std::cout << month << std::endl;
    }else{
      std::cout << "NA" << std::endl;
    }
  }
  return 0;
}

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

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

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define alint(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	while(1){
		int l,sum=0,ans=0;
		cin>>l;
		if(l==0) break;
		vi m(12),n(12);
		rep(i,0,12){
			cin>>m[i]>>n[i];
		}
		rep(i,0,12){
			sum+=m[i]-n[i];
			if(sum>=l){
				ans=i+1;
				break;
			}
		}
		if(ans==0) o("NA");
		else o(ans);
	}
}

C++: #include<iostream>

using namespace std;

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

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

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

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

int main()
{
  int L, M, N;
  
  while (scanf("%d", &L), L){
    int sum = 0, reach;
    bool check = true;
    for (int i = 0; i < 12; i++){
      scanf("%d%d", &M, &N);
      sum += M - N;
      if (check && sum >= L){
        reach = i + 1;
        check = false;
      }
    }
    if (!check){
      printf("%d\n", reach);
    }
    else {
      printf("NA\n");
    }
  }

  return (0);
}

C++: #include <iostream>
using namespace std;
int hoge(int *L){ cin >> *L; return *L;}
int main(){
	int L,M,N;
	while(hoge(&L)){
		int j=1;
		for(int i=0;i<12;i++){
			cin >> M >> N;
			L -= M-N;
			if(L>=0) j++;
		}
		if(L>0) cout << "NA" << endl;
		else cout <<  j << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

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

	while(1)
	{
		int sum = 0;
		int count = 0;
		int ans;
		cin >> L;

		if(L == 0)
		{
			break;
		}

		for(int i = 1; i <= 12; i++)
		{

			cin >> M >> N ;

			sum += M - N;

			if(sum >= L && count < 1)
				{
					count++;
					ans = i;
				}
		}

		if(sum >= L && count < 2)
				{
					cout << ans << endl;
				}	
		else
		{
			cout << "NA" << endl;
		}
	}


	return 0;
}

C++: #include <iostream>

using namespace std;

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

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
    for(;;){
	int l;
	int m[12];
	int n[12];
	int c=0;
	int ans=0;
	cin>>l;
	if(l==0)break;
	for(int i=0;i<12;i++){
        cin>>m[i]>>n[i];
	}
	for(int i=0;i<12;i++){
        c+=m[i]-n[i];
        if(c>=l){
            ans=i+1;
            break;
        }
	}
	if(ans==0)cout<<"NA"<<endl;
	else cout<<ans<<endl;

    }
	return 0;
}

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;
}