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 main(){
  bool flag;
  int M, N, L, ans, mon;
  while(1){
    ans = flag = 0;
    cin >> L;
    if(L == 0) break;
    for(int i = 1; i <= 12; i++){
      cin >> M >> N;
      ans += (M - N);
      if(L <= ans && flag == 0){
	flag = 1;
	mon = i;
      }
    }
    if(flag == 0) cout << "NA" << endl;
    else cout << mon << endl;
  }
}