Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
Here:
	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 Here
			}
		}
		fmt.Println("NA")
	}
}

Python: while True:
    L = int(input())
    if L == 0:
        break
    
    flag = True
    ans = -1
    d = 0
    for i in range(12):
        M,N = [int(i) for i in input().split()]
        d = d + M - N
        if d >= L and flag:
            ans = i+1
            flag = False
    
    if ans >= 0:
        print(ans)
    else:
        print("NA")

Python: while True:
    z = True
    a = int(input())
    if a == 0:
        break
    for i in range(12):
        b,c = map(int,input().split())
        a -= b-c
        if a <= 0 and z:
            print(i+1)
            z = False
    if a > 0:
        print("NA")

Python: while True:
    v = int(input())
    if v == 0:
        break
    
    c = 0
    f = 0
    for i in range(1,13):
        m, n = [int(x) for x in input().split()]
        c += m - n
        if f == 0 and c >= v:
            f = i
    
    if f > 0:
        print(f)
    else:
        print("NA")

Python: # AOJ 0206: Next Trip
# Python3 2018.6.25 bal4u

while True:
	L = int(input())
	if L == 0: break
	s, k = 0, 0
	for i in range(1, 13):
		m, n = map(int, input().split())
		s += m-n
		if s >= L and k == 0: k = i
	print(k if k > 0 else "NA")

Python: while True:
    
    #旅行費用を入力し0なら終わる
    num = int(input())
    if num == 0:break
    num_list = []
    
    #小遣いの差額をリストに追加していく
    for i in range(0,12):
        a,b = map(int,input().split())
        num_list.append(a - b)
        
    #12ヶ月ためても無理な場合は"NA"を出力する
    if num > sum(num_list):
        print("NA")
        continue
    
    #毎月減らしていき達成したらループを抜ける
    for i in range(0,12):
        num -= num_list[i]
        if num <= 0:break
    
    #リストに合わせるため変数を1減らしていたため1足して出力する
    print(i + 1)

Python: import sys

while True:
    L = int(input())
    if L == 0:
        break
    savings = 0
    a = [map(int, sys.stdin.readline().split()) for _ in [0]*12]
    for i, (M, N) in enumerate(a, start=1):
        savings += M - N
        if savings >= L:
            print(i)
            break
    else:
        print("NA")

Python: while(True):
    L = int(input())
    if not L:
        break
    a = 0
    b = 0
    c = 0
    for _ in range(12):
        a += 1
        M,N = map(int, input().split())
        b += M-N
        if not c and b >= L:
            c = a
    print(c if c else "NA")

Python: while True:
  L = int(input())
  if not L: break
  for i in range(1, 13):
    m, n = map(int, input().split())
    if L <= 0: continue
    c = i
    L -= m - n
  if L > 0:
    print('NA')
  else:
    print(c)

Python: while True:
    L= int(input())
    if L== 0: break
    mn= [list(map(int, input().split())) for _ in range(12)]
    ans=c=1
    b= True
    for m, n in mn:
        ans+= m-n
        if ans>= L:
            print(c)
            b= False
            break
        c+= 1
    if b: print("NA")

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0206

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    while True:
        L = int(input())
        if L == 0:
            break
        ans = 'NA'
        for i in range(1, 12+1):
            M, N = map(int, input().split())
            if ans == 'NA':
                L -= (M - N)
                if L <= 0:
                    ans = i
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Python: while 1:
    n=int(input())
    if n==0: break
    for i in range(12):
        a,b=map(int,input().split())
        if n<=0: continue
        c=i+1
        n-=a-b
    if n>0:print("NA")
    else:print(c)

Python: 
def algorithm():
    while True:
        budget = int(input())
        if budget == 0:
            break

        total, months = 0, 0
        for _ in range(12):
            income, outcome = map(int, input().split())
            total += income - outcome
            if total >= budget and months == 0:
                months = _ + 1

        print('NA' if total < budget else months)


def main():
    algorithm()


if __name__ == '__main__':
    main()

Python: from sys import stdin
readline = stdin.readline


from itertools import accumulate

while True:
    trip_cost = int(readline())
    if trip_cost == 0:
        break
    saving = []
    for _ in range(12):
        income, outgo = map(int, readline().split())
        saving.append(income - outgo)

    for i, accumulative_saving in enumerate(accumulate(saving)):
        if trip_cost <= accumulative_saving:
            print(i + 1)
            break
    else:
        print('NA')

Python: # Aizu Problem 0206: The Next Trip

import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def next_trip(L, cashflow):
    saved = 0
    month = 0
    for m, n in cashflow:
        month += 1
        saved += (m - n)
        if saved >= L:
            return month
    return "NA"

    
while True:
    L = int(input())
    if L == 0:
        break
    cashflow = [[int(_) for _ in input().split()] for __ in range(12)]
    print(next_trip(L, cashflow))

Python: while True :
    l = int(input())
    if l == 0 :
        break
    
    money = 0
    END = False
    for i in range(12) :
        m, n = map(int, input().split())
        money += m - n
        
        if money >= l and END == False :
            month = i + 1
            END = True
    
    if END == False :
        print("NA")
    else :
        print(month)

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0206

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    while True:
        L = int(input())
        if L == 0:
            break
        ans = 'NA'
        for i in range(1, 12+1):
            if ans == 'NA':
                M, N = map(int, input().split())
                L -= (M - N)
                if L <= 0:
                    ans = i
            else:
                _ = input()
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Python: def alogrithm():
    while True:
        budget = int(input())
        if budget == 0:
            break

        total = 0
        months = 0
        for _ in range(12):
            income, outcome = map(int, input().split())
            total += income - outcome
            months += 1 if income > outcome else 0

        if total < budget:
            print('NA')
        else:
            print(months)


def main():
    alogrithm()


if __name__ == '__main__':
    main()

Python: while True:
  l = int(input())
  if l == 0:
    break
  acc = 0
  ans = 0
  for i in range(1, 13):
    m, n = map(int, input().split())
    acc += (m - n)
    if not ans and acc >= l:
      ans = i
  if not ans:
    print("NA")
  else:
    print(ans)

Python: while True:
    L= int(input())
    if L== 0: break
    mn= [list(map(int, input().split())) for _ in range(12)]
    ans=c=0
    b= True
    for m, n in mn:
        ans+= m-n
        c+= 1
        if ans>= L:
            print(c)
            b= False
            break
    if b: print("NA")

Python: while True:
    L=int(input())
    if L==0:
        break
    S=0
    B=0
    for i in range(1,13):
        M,N=map(int,input().split())
        A=M-N
        S+=A
        if S>=L and B==0:
            B=i
    if B>0:
        print(B)
    else:
        print("NA")