Title: When is the Trip?

You are considering going on a trip with a friend. However, your friend, who has a habit of overspending, struggles to save up for the trip. If your friend continues their current lifestyle, it's uncertain when the trip will happen. To expedite the trip, you decide to create a program to help your friend save systematically.

Given the allowance for a specific month as M yen and the amount spent in that month as N yen, the savings for that month will be (M - N) yen. Create a program that takes the monthly income and expenses (M, N) as input and outputs the number of months it will take for the savings to reach the travel cost L. If the savings do not reach the travel cost even after 12 months, output "NA".

Input:
Multiple datasets are provided as input until a single zero is encountered.
Each dataset is in the following format:
L
M1 N1
M2 N2
...
M12 N12

The first line contains the travel cost L (1 ≤ L ≤ 1000000, integer). The subsequent 12 lines contain the income and expense information for the i-th month, M_i, N_i (0 ≤ M_i, N_i ≤ 100000, N_i ≤ M_i, integers).

The number of datasets does not exceed 1000.

Output:
For each input dataset, output the number of months it will take for the savings to reach the travel cost on a single line.

Sample Input:
10000
5000 3150
5000 5000
0 0
5000 1050
5000 3980
5000 210
5000 5000
5000 5000
0 0
5000 2100
5000 2100
5000 2100
29170
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 100000
100000 70831
0

Output for the Sample Input:
6
NA

# Buggy version:
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()

# Fixed version:

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()

# Buggy version:
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")

# Fixed version:
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")