It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive him there. The only choice for this poor little boy is to wait for a bus on this rainy day. Under such circumstances, the poor boy will use the first bus he sees no matter where it goes. If several buses come at the same time, he will choose one randomly.

Serval will go to the bus station at time $t$, and there are $n$ bus routes which stop at this station. For the $i$-th bus route, the first bus arrives at time $s_i$ minutes, and each bus of this route comes $d_i$ minutes later than the previous one.

As Serval's best friend, you wonder which bus route will he get on. If several buses arrive at the same time, you can print any of them.


-----Input-----

The first line contains two space-separated integers $n$ and $t$ ($1\leq n\leq 100$, $1\leq t\leq 10^5$) — the number of bus routes and the time Serval goes to the station. 

Each of the next $n$ lines contains two space-separated integers $s_i$ and $d_i$ ($1\leq s_i,d_i\leq 10^5$) — the time when the first bus of this route arrives and the interval between two buses of this route.


-----Output-----

Print one number — what bus route Serval will use. If there are several possible answers, you can print any of them.


-----Examples-----
Input
2 2
6 4
9 5

Output
1

Input
5 5
3 3
2 5
5 6
4 9
6 1

Output
3

Input
3 7
2 2
2 3
2 4

Output
1



-----Note-----

In the first example, the first bus of the first route arrives at time $6$, and the first bus of the second route arrives at time $9$, so the first route is the answer.

In the second example, a bus of the third route arrives at time $5$, so it is the answer.

In the third example, buses of the first route come at times $2$, $4$, $6$, $8$, and so fourth, buses of the second route come at times $2$, $5$, $8$, and so fourth and buses of the third route come at times $2$, $6$, $10$, and so on, so $1$ and $2$ are both acceptable answers while $3$ is not.

Difficulty: EASY
Tags: Mathematics

Complete search
Skill types: Complete search

Starter code:

Solutions:
I = lambda : map(int, input().split())
(n, t) = I()
T = []
for _ in range(n):
	(s, d) = I()
	s -= t
	T.append(s % d if s < 0 else s)
print(T.index(min(T)) + 1)


from collections import defaultdict, deque
(n, t) = map(int, input().split())
res = []
for _ in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		res.append(s)
	else:
		steps = (t - s + (d - 1)) // d
		res.append(s + steps * d)
print(res.index(min(res)) + 1)


(n, t) = [int(x) for x in input().split()]
answer = 10 ** 100
total = 0
for i in range(n):
	(time, d) = [int(x) for x in input().split()]
	if time < t:
		if (t - time) % d != 0:
			counter = t - (t - time) % d + d
		else:
			counter = t
	else:
		counter = time
	if counter < answer:
		answer = counter
		total = i + 1
print(total)


(N, T) = list(map(int, input().split()))
bt = -1
br = -1
for n in range(N):
	(s, d) = list(map(int, input().split()))
	if s >= T:
		a = s
	else:
		a = (T - s + d - 1) // d
		a = s + d * a
	if bt == -1 or a < bt:
		bt = a
		br = n + 1
print(br)


import math
(n, t) = map(int, input().split())
buses_arr = []
buses_freq = []
for i in range(n):
	(a, b) = map(int, input().split())
	buses_arr.append(a)
	buses_freq.append(b)
for i in range(len(buses_arr)):
	if buses_arr[i] < t:
		buses_arr[i] += math.ceil((t - buses_arr[i]) / buses_freq[i]) * buses_freq[i]
print(buses_arr.index(min(buses_arr)) + 1)


(n, m) = map(int, input().split())
ans = 0
lar = 10 ** 9
for i in range(n):
	(s, t) = map(int, input().split())
	x = (m - s) // t
	while x < 0 or s + t * x < m:
		x += 1
	if lar > s + t * x:
		lar = s + t * x
		ans = i + 1
print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	(n, t) = LI()
	aa = [LI() for _ in range(n)]
	m = inf
	r = -1
	for i in range(n):
		(s, d) = aa[i]
		if s < t:
			s += (t - s + d - 1) // d * d
		if s < m:
			m = s
			r = i
	return r + 1
print(main())


import math

def main_function():
	min_time = 1000000000
	min_index = 0
	(n, t) = [int(i) for i in input().split(' ')]
	s_d = [[int(i) for i in input().split(' ')] for j in range(n)]
	for i in range(len(s_d)):
		(s, d) = s_d[i]
		min_time_1 = s + max(0, math.ceil((t - s) / d)) * d - t
		index = i + 1
		if min_time > min_time_1:
			min_time = min_time_1
			min_index = index
	print(min_index)
main_function()


from math import ceil
(a, b) = map(int, input().split())
closest = 0
mini = 0
for i in range(a):
	(x, y) = map(int, input().split())
	if x >= b:
		if mini == 0 or x < mini:
			closest = i + 1
			mini = x
	else:
		u = x + y * ceil((b - x) / y)
		if u < mini or mini == 0:
			mini = u
			closest = i + 1
print(closest)


(n, t) = map(int, input().split())
mn = 10 ** 100
piv = -1
for i in range(n):
	(s, d) = map(int, input().split())
	if t < s:
		if s < mn:
			mn = s
			piv = i + 1
		continue
	p = (t - s + d - 1) // d
	if mn > s + p * d:
		mn = s + p * d
		piv = i + 1
print(piv)


L1 = [int(item) for item in input().split(' ')]
arr_time = L1[1]
buses = []
for item in range(L1[0]):
	temp = [int(item) for item in input().split(' ')]
	buses.append(temp)
res_list = []
for item in buses:
	if arr_time <= item[0]:
		temp = item[0] - arr_time
	elif (arr_time - item[0]) % item[1] == 0:
		temp = 0
	else:
		helper = int((arr_time - item[0]) / item[1]) + 1
		temp = item[0] + item[1] * helper - arr_time
	res_list.append(temp)
print(res_list.index(min(res_list)) + 1)


(n, t) = map(int, input().split())
(s, d) = map(int, input().split())
while s < t:
	s += d
min = s
ans = 1
for i in range(n - 1):
	(s, d) = map(int, input().split())
	while s < t:
		s += d
	if s < min:
		min = s
		ans = i + 2
	if s == t:
		break
print(ans)


kk = lambda : map(int, input().split())
ll = lambda : list(kk())
(n, t) = kk()
(mv, j) = (10000000000, -1)
for i in range(n):
	(s, d) = kk()
	while s < t:
		s += d
	if s < mv:
		(mv, j) = (s, i)
print(j + 1)


firstline = [int(n) for n in input().split()]
n = 0
s = 1
dis = []
while n in range(firstline[0]):
	s = 1
	bus = [int(n) for n in input().split()]
	dist = bus[1] - (firstline[1] - bus[0]) % bus[1]
	if firstline[1] <= bus[0]:
		dist = bus[0] - firstline[1]
		s = 2
	if dist == bus[1] and s == 1:
		print(n + 1)
		s = 3
		break
	else:
		dis.append(dist)
	n += 1
if s != 3:
	print(dis.index(min(dis)) + 1)


import math
(n, t) = map(int, input().split())
sd = [list(map(int, input().split())) for i in range(n)]
timediv = [max(0, math.ceil((t - sd[i][0]) / sd[i][1])) * sd[i][1] + sd[i][0] for i in range(n)]
print(timediv.index(min(timediv)) + 1)


(n, t) = map(int, input().split())
l = []
z = []
for i in range(n):
	(a, b) = map(int, input().split())
	a = a - t
	if a < 0:
		a = a % b
	l.append(a)
	z.append(b)
print(l.index(min(l)) + 1)


(n, t) = map(int, input().split())
a = []
b = []
for i in range(n):
	(s, d) = map(int, input().split())
	if s == t:
		print(i + 1)
		exit()
	else:
		a.append(s)
		b.append(d)
if t <= min(a):
	print(a.index(min(a)) + 1)
else:
	c = []
	for i in range(n):
		if t <= a[i]:
			c.append(a[i] - t)
		elif (t - a[i]) % b[i] == 0:
			c.append(0)
		else:
			c.append(b[i] - (t - a[i]) % b[i])
	print(c.index(min(c)) + 1)


(n, t) = map(int, input().split())
random_bus = 0
start = float('inf')
for (ind, bus) in enumerate(range(n)):
	(s, d) = map(int, input().split())
	if t <= s:
		if s < start:
			start = s
			random_bus = ind + 1
	else:
		s += d * ((t - s) // d + 1) if (t - s) % d != 0 else d * ((t - s) // d)
		if s < start:
			start = s
			random_bus = ind + 1
print(random_bus)


import sys
(n, t) = map(int, sys.stdin.readline().split())
temp = []
ans = []
for i in range(n):
	(a, b) = map(int, sys.stdin.readline().split())
	temp.append((a, b, i + 1))
for i in temp:
	now = 1
	(a, b, c) = i
	while b * now - b + a < t:
		now += 1
	ans.append((b * now - b + a, c))
ans.sort()
print(ans[0][1])


import math
(n, t) = input().split()
(n, t) = (int(n), int(t))
m = 99999999
mini = 0
for i in range(n):
	(s, d) = input().split()
	(s, d) = (int(s), int(d))
	if s > t:
		a = s
	else:
		a = math.ceil((t - s) / d) * d + s
	if a < m:
		m = a
		mini = i + 1
print(mini)


(n, t) = map(int, input().split())
a = []
for i in range(n):
	(x, y) = map(int, input().split())
	if x >= t:
		a.append(x)
	else:
		while x < t:
			x += y
		a.append(x)
q = a.index(min(a)) + 1
print(q)


import sys
input = sys.stdin.readline

def main():
	(n, t) = map(int, input().split())
	r = float('inf')
	road = -1
	for i in range(n):
		(si, di) = map(int, input().split())
		if si >= t:
			if si < r:
				road = i
				r = si
		elif (t - si) % di == 0:
			if t < r:
				road = i
				r = t
		elif si + ((t - si) // di + 1) * di < r:
			road = i
			r = si + ((t - si) // di + 1) * di
	print(road + 1)
main()


from math import ceil
(X, Bus) = (list(map(int, input().split())), [])
for i in range(X[0]):
	Temp = list(map(int, input().split()))
	if Temp[0] == X[1]:
		print(i + 1)
		exit()
	Bus.append(Temp[0] if Temp[0] > X[1] else Temp[1] * ceil((X[1] - Temp[0]) / Temp[1]) + Temp[0])
print(Bus.index(min(Bus)) + 1)


(n, t) = list(map(int, input('').split()))
a = [list(map(int, input('').split())) for i in range(n)]
nul = [i[0] for i in a]
inter = [i[1] for i in a]
time = [nul[i] - t if t < nul[i] else (-t + nul[i]) % inter[i] for i in range(n)]
s = min(time)
print(time.index(s) + 1)


(n, t) = map(int, input().split())
i = 0
dmin = None
imin = None
for i in range(n):
	i += 1
	(s, d) = map(int, input().split())
	while s < t:
		s += d
	if dmin == None or s - t < dmin:
		dmin = s - t
		imin = i
print(imin)


(n, t) = map(int, input().split())
ls = []
bus = 0
best_time = 10000000
for i in range(1, n + 1):
	(s, d) = map(int, input().split())
	s = s - t
	if s < 0:
		s = s % d
	ls.append(s)
selected = ls.index(min(ls)) + 1
print(selected)


import sys
(n, t) = map(int, input().split())
min_val = sys.maxsize
ind = 0
for i in range(n):
	(s, d) = map(int, input().split())
	val = (t - s) // d
	if val < 0:
		val = 0
	elif (t - s) % d != 0:
		val = val + 1
	time = s + d * val
	if time < min_val:
		min_val = time
		ind = i
print(ind + 1)


from sys import stdin
import math
(n, t) = map(int, stdin.readline().split())
a = [tuple(map(int, stdin.readline().split())) for i in range(n)]

def first_arrive_time(s, d, t):
	while s < t:
		s += d
	return s
print(min(enumerate(a, 1), key=lambda x: first_arrive_time(x[1][0], x[1][1], t))[0])


(n, t) = map(int, input().split())
si = []
di = []
array = []
minim = 0
for i in range(n):
	(s, d) = map(int, input().split())
	si.append(s)
	di.append(d)
if t in si:
	print(si.index(t) + 1)
else:
	for i in range(n):
		if si[i] < t:
			array.append((si[i] - t) % di[i])
		else:
			array.append(si[i] - t)
	print(array.index(min(array)) + 1)


(n, t) = map(int, input().split())
min_dist = 10000000
min_num = 0
for i in range(n):
	(s, d) = map(int, input().split())
	if s < t and (s - t) % d < min_dist:
		min_dist = (s - t) % d
		min_num = i + 1
	elif s >= t and s - t < min_dist:
		min_dist = s - t
		min_num = i + 1
print(min_num)


import math
(n, t) = map(int, input().split())
mt = 999999
ma = 0
for i in range(n):
	(s, d) = map(int, input().split())
	k = math.ceil(max(0, (t - s) / d)) * d + s
	if k < mt:
		mt = k
		ma = i + 1
print(ma)


R = lambda : map(int, input().split())
(n, t) = R()
a = []
for i in range(n):
	(s, d) = R()
	s -= t
	if s < 0:
		s = s % d
	a.append(s)
print(a.index(min(a)) + 1)


(n, t) = [int(i) for i in input().split(' ')]
res = float('inf')
minn = 1
for i in range(n):
	(ss, dd) = [int(i) for i in input().split(' ')]
	if ss < t:
		tmp = 0 if (t - ss) % dd == 0 else dd - (t - ss) % dd
		if tmp < res:
			minn = i + 1
		res = min(res, tmp)
	elif ss == t:
		minn = i + 1
		break
	else:
		if ss - t < res:
			minn = i + 1
		res = min(res, ss - t)
print(minn)


import sys, math as mt
import heapq as hp
import collections as cc
import bisect as bi
import math as mt
import itertools as it
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n, t) = I()
ans = []
for i in range(n):
	(a, b) = I()
	a -= t
	if a < 0:
		a = a % b
	ans.append(a)
print(ans.index(min(ans)) + 1)


def main():
	s = [int(x) for x in input().split()]
	n = s[0]
	t = s[1]
	ans = 1000000000
	bus = 0
	for i in range(n):
		a = [int(x) for x in input().split()]
		s = a[0]
		d = a[1]
		if s >= t:
			t1 = s
		else:
			t1 = s + (t - s + d - 1) // d * d
		if t1 <= ans:
			ans = t1
			bus = i + 1
	print(bus)
main()


(n, m) = map(int, input().split())
(ans, ans_t) = (-1, 10000000000000)

def update(i, t):
	global ans, ans_t
	if t < ans_t:
		ans = i
		ans_t = t
for i in range(1, n + 1):
	(u, v) = map(int, input().split())
	if m <= u:
		update(i, u)
	else:
		update(i, u + (int((m - u) / v) + int(bool((m - u) % v))) * v)
print(ans)


(n, t) = map(int, input().split())
k = 0
mini = 0
for i in range(n):
	(s, d) = map(int, input().split())
	while s < t:
		s += d
	if i == 0:
		mini = s
	elif s < mini:
		mini = s
		k = i
print(k + 1)


def tmax(m, t):
	if m[0] >= t:
		return m[0]
	else:
		return t + (m[1] - (t - m[0]) % m[1]) % m[1]
(n, t) = map(int, input().split())
print(min([(tmax(list(map(int, input().split())), t), i + 1) for i in range(n)])[1])


(n, t) = map(int, input().split())
r = 1000000000000000000000
for i in range(n):
	(s, d) = map(int, input().split())
	x = max((t - s + d - 1) // d, 0)
	to = s + x * d
	if to < r:
		r = to
		ri = i + 1
print(ri)


import math
(n, t) = input().split(' ')
n = int(n)
t = int(t)
min = 10000000
x = None
y = None
ind = None
for i in range(n):
	(x, y) = input().split(' ')
	x = int(x)
	y = int(y)
	if x < t:
		x = x + t // y * y
		if x > t:
			x = x + int(math.ceil((t - x) / y)) * y
	if x < t:
		x = x + y
	if x <= min:
		min = x
		ind = i + 1
print(ind)


line = list(map(int, input().split()))
n = line[0]
t = line[1]
myMin = 2000000000
firstBus = 0
for i in range(0, n):
	line = list(map(int, input().split()))
	s = line[0]
	d = line[1]
	if t < s:
		if s < myMin:
			myMin = s
			firstBus = i + 1
	else:
		x = (t - s) // d
		if s + d * x < t:
			x = x + 1
		if s + d * x < myMin:
			myMin = s + d * x
			firstBus = i + 1
print(str(firstBus))


import sys
input = sys.stdin.readline
(n, t) = map(int, input().split())
ans = 1 << 60
l = []
for i in range(n):
	(s, d) = map(int, input().split())
	if s < t:
		s = (t - s + d - 1) // d * d + s
	l.append([s, i + 1])
l.sort()
print(l[0][1])


inputs = [int(x) for x in input().split()]
time = inputs[1]
minTime = 10 ** 5
bus = -1
for i in range(inputs[0]):
	inp = [int(x) for x in input().split()]
	totalTime = 0
	if time < inp[0]:
		totalTime = inp[0] - time
	else:
		totalTime = (inp[0] - time) % inp[1]
	if totalTime < minTime:
		bus = i + 1
		minTime = totalTime
print(int(bus))


from math import ceil
(n, t) = map(int, input().split())
buses = []
for i in range(n):
	(s, d) = map(int, input().split())
	buses.append([s, d, i])
buses = sorted(buses)
for i in range(n):
	if buses[i][0] < t:
		diff = t - buses[i][0]
		mult = ceil(diff / buses[i][1])
		buses[i][0] += mult * buses[i][1]
buses = sorted(buses)
ans = buses[0][2] + 1
print(ans)


(n, t) = map(int, input().split())
ans = None
wait = 1000000000.0
for i in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		a = s - t
	elif (t - s) % d == 0:
		a = 0
	else:
		a = d - (t - s) % d
	if a < wait:
		wait = a
		ans = i + 1
print(ans)


import sys

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().strip()

def main():
	(n, t) = get_ints()
	arr = [0] * n
	for i in range(n):
		arr[i] = get_array()
	vis = [0] * (2 * 10 ** 5 + 5)
	for i in range(n):
		curr = arr[i][0]
		while curr < 2 * 10 ** 5 + 5:
			vis[curr] = i + 1
			curr += arr[i][1]
	for i in range(t, 2 * 10 ** 5 + 5):
		if vis[i] != 0:
			print(vis[i])
			return
main()


import math

def serval_bus():
	buses = list(map(int, input().split()))
	times = []
	minimum = math.inf
	index = 0
	for i in range(buses[0]):
		times.append(list(map(int, input().split())))
		if times[i][0] == buses[1]:
			return i + 1
		elif times[i][0] > buses[1]:
			if times[i][0] - buses[1] < minimum:
				minimum = times[i][0] - buses[1]
				index = i + 1
	for i in range(len(times)):
		if times[i][0] > buses[1]:
			if times[i][0] - buses[1] < minimum:
				minimum = times[i][0] - buses[1]
				index = i + 1
			continue
		add = times[i][1]
		times[i][1] = times[i][0] + add
		temp = buses[1] - times[i][1]
		times[i][1] += math.ceil(temp / add) * add
		if times[i][1] == buses[1]:
			return i + 1
		elif times[i][1] > buses[1]:
			if times[i][1] - buses[1] < minimum:
				minimum = times[i][1] - buses[1]
				index = i + 1
	return index
A = serval_bus()
print(A)


import math
(n, t) = list(map(int, input().split()))
time = math.inf
arr2 = []
index = 0
ind = 0
for _ in range(n):
	ind += 1
	(s, d) = list(map(int, input().split()))
	if s >= t:
		if time > s:
			time = s
			index = ind
	else:
		z = math.ceil((t - s) / d)
		s += z * d
		if time > s:
			time = s
			index = ind
print(index)


from math import ceil
(m, n) = map(int, input().split())
(ans, x) = (9999999999999999999999, 1)
for i in range(m):
	(a, b) = map(int, input().split())
	if a < n:
		a += ceil((n - a) / b) * b
	if a - n < ans:
		ans = a - n
		x = i + 1
print(x)


import math
(n, t) = map(int, input().split())
a = []
for i in range(n):
	x = list(map(int, input().split()))
	a.append(x)
b = a.copy()
a.sort()
for j in range(n):
	if a[j][0] < t:
		a[j][0] += a[j][1] * math.ceil((t - a[j][0]) / a[j][1])
	else:
		break
a.sort()
print(b.index(a[0]) + 1)


import sys

def Ints():
	return map(int, sys.stdin.readline().strip().split())

def Strs():
	return map(str, sys.stdin.readline().strip().split())

def Array():
	return list(map(int, sys.stdin.readline().strip().split()))

def Str():
	return sys.stdin.readline().strip()

def Int():
	return int(sys.stdin.readline().strip())

def MOD():
	return 1000000007

def power(base, power):
	MOD = 1000000007
	result = 1
	while power > 0:
		if power % 2 == 1:
			result = result * base % MOD
		power = power // 2
		base = base * base % MOD
	return result
(n, t) = Ints()
arr = []
for i in range(n):
	(s, d) = Ints()
	while s < t:
		s += d
	if s == t:
		print(i + 1)
		exit()
	arr.append(s)
mn = float('inf')
indx = -1
for i in range(n):
	if mn > arr[i] - t:
		mn = arr[i] - t
		indx = i
	if mn == 0:
		break
print(indx + 1)


(n, t) = map(int, input().split())
route = []
for i in range(n):
	route.append(list(map(int, input().split())) + [i + 1])
arrival = []
for i in range(n):
	arrival.append([max(route[i][0] - t, (route[i][0] - t) % route[i][1]), i + 1])
arrival
arrival.sort()
print(arrival[0][1])


(n, t) = [int(k) for k in input().split(' ')]
mw = 100000000000000
nbest = -1
for i in range(n):
	(s, d) = [int(k) for k in input().split(' ')]
	if t < s:
		w = s - t
	else:
		w = (d - (t - s)) % d
	if w < mw:
		mw = w
		nbest = i + 1
print(nbest)


import math
(n, t) = map(int, input().split())
fr = []
dl = []
t1 = 10000000000
i1 = -1
for i in range(n):
	(c1, c2) = map(int, input().split())
	fr.append(c1)
	dl.append(c2)
for i in range(n):
	if fr[i] < t:
		fr[i] += dl[i] * math.ceil((t - fr[i]) / dl[i])
	if fr[i] < t1:
		t1 = fr[i]
		i1 = i
print(i1 + 1)


from math import ceil
(n, t) = map(int, input().split())
dif = []
for i in range(n):
	(t0, d) = map(int, input().split())
	if t0 > t:
		dif.append(t0 - t)
	else:
		e = t0 + d * ceil((t - t0) / d) - t
		if not e:
			print(i + 1)
			break
		else:
			dif.append(e)
else:
	print(1 + dif.index(min(dif)))


from math import ceil
(n, t) = map(int, input().split())
_min = int(10000000000.0)
mark = -1
for i in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		if _min > s:
			_min = s
			mark = i
	else:
		x = ceil((t - s) / d)
		if _min > s + x * d:
			_min = s + x * d
			mark = i
print(mark + 1)


(n, t) = map(int, input().split())
(b, dif) = (-1, 10000000000)
for i in range(n):
	(s, d) = map(int, input().split())
	a = t - s
	if a <= 0:
		d = -a
	else:
		d = -a % d
	if d < dif:
		b = i + 1
		dif = d
print(b)


import sys, math, queue
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
(n, t) = map(int, input().split())
a = []
for i in range(n):
	(si, di) = map(int, input().split())
	ti = max(0, math.ceil((t - si) / di) * di) + si
	a.append(ti)
indx = 1
ans = a[0]
for i in range(n):
	if a[i] < ans:
		ans = a[i]
		indx = i + 1
print(indx)


import math
(n, t) = map(int, input().split())
(mn, mn_time) = (0, math.inf)
for i in range(n):
	(s, d) = map(int, input().split())
	num_buses = max(math.ceil((t - s) / d), 0)
	time_for_bus = s + num_buses * d
	if time_for_bus < mn_time:
		mn_time = time_for_bus
		mn = i + 1
print(mn)


n = 0
arrival = 0
bus = 0
interval = 0
result = 0
list = []
dic = dict()
m = dict()
set1 = set()
l = []
l = input()
l = l.split()
for i in range(len(l)):
	l[i] = int(l[i])
n = l[0]
arrival = l[1]
l.clear()
ii = 0
for i in range(n):
	l.clear()
	l = input()
	l = l.split()
	for j in range(len(l)):
		l[j] = int(l[j])
	a = l[0]
	b = l[1]
	if not (a, b) in m.values():
		m[ii] = (a, b)
		ii += 1
	else:
		ii += 1
for (i, (x, y)) in m.items():
	bus = x
	interval = y
	if arrival == bus:
		dic[i + 1] = 0
	else:
		while arrival > bus:
			if bus + interval != arrival:
				num = arrival // (interval + bus)
				bus += (num + 1) * interval
			else:
				bus = arrival = 0
		dic[i + 1] = bus - arrival
result = min(dic, key=dic.get)
print(result)


(n, t) = map(int, input().split())
lst1 = []
for i in range(n):
	lst = list(map(int, input().split()))
	lst1.append(lst)
for i in range(len(lst1)):
	if lst1[i][0] == t:
		print(i + 1)
		k = 1
		break
	else:
		k = 0
if k == 0:
	dict1 = {}
	for i in range(len(lst1)):
		while True:
			if lst1[i][0] >= t:
				dict1[lst1[i][0] - t] = i + 1
				break
			else:
				lst1[i][0] += lst1[i][1]
	lst3 = []
	min1 = 10000000000
	for i in dict1:
		if i < min1:
			min1 = i
	print(dict1[min1])


(n, t) = map(int, input().split())
arr = []
for i in range(n):
	(s, d) = map(int, input().split())
	arr.append([s, d, i + 1])
for i in range(n):
	(s, d, route) = arr[i]
	if t > s:
		arr[i][0] += ((t - s - 1) // d + 1) * d
arr.sort()
print(arr[0][2])


(n, t) = map(int, input().split())
A = []
for i in range(n):
	(s, d) = map(int, input().split())
	x = d - (t - s) % d
	if x == d:
		x = 0
	if t + x < s:
		x = s - t
	A.append((x, i + 1))
print(min(A)[1])


import math

def main():
	(n, t) = map(int, input().split())
	l = list(enumerate([list(map(int, input().split())) for i in range(n)]))
	l = min(l, key=lambda x: x[1][0] + x[1][1] * math.ceil((t - x[1][0]) / x[1][1]) if t > x[1][0] else x[1][0])
	print(l[0] + 1)
main()


from math import ceil
(n, t) = tuple(map(int, input().split()))
list_s = []
list_d = []
for i in range(n):
	(x, y) = tuple(map(int, input().split()))
	list_s.append(x)
	list_d.append(y)
list_llegada = []
for i in range(n):
	numero = ceil((t - list_s[i]) / list_d[i])
	if numero < 0:
		numero = 0
	list_llegada.append(list_s[i] + numero * list_d[i])
	if i == 0:
		numero_menor = list_llegada[-1]
		posicion = 0
	elif numero_menor > list_llegada[-1]:
		numero_menor = list_llegada[-1]
		posicion = i
print(posicion + 1)


(n, t) = [int(j) for j in input().split()]
time = 1000000
bus = None
for i in range(n):
	(arrive, interlude) = [int(j) for j in input().split()]
	if t > arrive:
		arrive += (t - arrive) // interlude * interlude
	if arrive < t:
		arrive += interlude
	if arrive < time:
		time = arrive
		bus = i + 1
print(bus)


import math
(n, t) = map(int, input().split())
ans = []
for i in range(n):
	(a, b) = map(int, input().split())
	if a >= t:
		ans.append(a - t)
	else:
		k = math.ceil((t - a) / b) * b + a - t
		ans.append(k)
ind = 0
prev = 100000000
for i in range(len(ans)):
	if ans[i] < prev:
		prev = ans[i]
		ind = i + 1
print(ind)


(n, t) = map(int, input().split())
A = []
for i in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		A.append(s - t)
	else:
		A.append((d - (t - s) % d) % d)
print(A.index(min(A)) + 1)


(n, t) = map(int, input().split())
flag = True
ans = (float('inf'), -1)
l = list()
for i in range(n):
	(s, d) = map(int, input().split())
	curr_time = (t - s) / d
	if curr_time < 0:
		curr_time = 0
		flag = False
	elif int(curr_time) != curr_time:
		curr_time = int(curr_time) + 1
	curr_time = curr_time * d + s
	if ans[0] > curr_time:
		ans = (curr_time, i + 1)
	l.append(curr_time)
print(ans[1])


(n, t) = map(int, input().split())
l = []
for i in range(n):
	(s, d) = map(int, input().split())
	s = s - t
	if s < 0:
		s = s % d
	l.append(s)
print(l.index(min(l)) + 1)


(x, t) = map(int, input().split())
minm = float('inf')
minm_i = 0
for i in range(x):
	(s, d) = map(int, input().split())
	ti = s
	if t > s:
		temp = (t - s) // d
		y = temp if (t - s) % d == 0 else temp + 1
		ti = y * d + s
	else:
		ti = s
	if ti < minm:
		minm = ti
		minm_i = i + 1
print(minm_i)


def serval(n, t, a):
	minx = 200000
	for i in range(n):
		if t <= a[i][0]:
			if a[i][0] - t < minx:
				minx = a[i][0] - t
				car = i
		elif (a[i][0] - t) % a[i][1] < minx:
			minx = (a[i][0] - t) % a[i][1]
			car = i
	return car + 1
(a, b) = input().strip().split()
a = int(a)
b = int(b)
y = []
for i in range(a):
	x = []
	(v, w) = input().strip().split()
	v = int(v)
	w = int(w)
	x.append(v)
	x.append(w)
	y.append(x)
print(serval(a, b, y))


(n, t) = map(int, input().split())
l = []
for i in range(n):
	(s, d) = map(int, input().split())
	if s < t:
		if (t - s) % d == 0:
			q = (t - s) // d
		else:
			q = (t - s) // d + 1
		l.append([s + q * d, i + 1])
	else:
		l.append([s, i + 1])
l.sort(key=lambda x: x[0])
print(l[0][1])


[n, t] = [int(el) for el in input().split()]
min_time = 2000001
bus_line = 101
for i in range(n):
	[start, interval] = [int(el) for el in input().split()]
	if min_time == t:
		continue
	while start < t:
		start += interval
	if start < min_time:
		min_time = start
		bus_line = i + 1
print(bus_line)


import sys
read = sys.stdin.readline
read = input
(n, t) = list(map(int, read().split()))
inter = [-1] * n
arrive = [-1] * n
for i in range(n):
	(a, b) = list(map(int, read().split()))
	arrive[i] = a
	inter[i] = b
	result = [-1] * n
for i in range(n):
	if (t - arrive[i]) % inter[i] == 0:
		if t - arrive[i] >= 0:
			result[i] = 0
		else:
			k = 0
			result[i] = arrive[i] - t
	elif t - arrive[i] < 0:
		k = 0
		result[i] = arrive[i] - t
	else:
		k = (t - arrive[i]) // inter[i] + 1
		result[i] = arrive[i] + inter[i] * k - t
min_idx = -1
min_val = 10 ** 6 + 1
for i in range(len(result)):
	if result[i] <= min_val:
		min_idx = i + 1
		min_val = result[i]
print(min_idx)


import math

def servalAndBus(n, t):
	si = []
	df = []
	tf = 10 ** 5
	sumaFinal = 0
	for i in range(n):
		(o, p) = map(int, input().split())
		si.append(o)
		df.append(p)
		if si[i] == t:
			return i + 1
		else:
			s = int(si[i])
			d = int(df[i])
			dif = t - s
			suma = max(math.ceil(dif / d), 0)
			final = suma * d + s - t
			if tf > final:
				tf = final
				sumaFinal = i + 1
	return sumaFinal
(n, t) = map(int, input().split())
print(servalAndBus(n, t))


sol = 0
mn = 10 ** 9
(n, t) = map(int, input().split())
for i in range(n):
	(s, d) = map(int, input().split())
	if s < t:
		s = t + (d - (t - s) % d) % d
	if s < mn:
		sol = i + 1
		mn = s
print(sol)


import sys
(n, t) = map(int, input().split())
ss = [0] * n
dd = [0] * n
for i in range(n):
	(ss[i], dd[i]) = map(int, input().split())
ans = -1
ansTime = 10 ** 11
for i in range(n):
	if ss[i] > t:
		curTime = ss[i]
	else:
		curTime = ss[i] + (t - ss[i] + dd[i] - 1) // dd[i] * dd[i]
	if curTime < ansTime:
		ans = i + 1
		ansTime = curTime
print(ans)


(n, m) = map(int, input().split())
s = []
for i in range(n):
	s += [list(map(int, input().split()))]
l = [0] * n
for i in range(n):
	if s[i][0] > m:
		l[i] = s[i][0] - m
	elif s[i][0] <= m:
		t = s[i][0] - m
		t = t % s[i][1]
		l[i] = t
l = [abs(i) for i in l]
minn = min(l)
for i in range(n):
	if l[i] == minn:
		print(i + 1)
		exit()


(n, t) = map(int, input().split())
sdi = [list(map(int, input().split())) for i in range(n)]
time = 1000000000000
ans = 1
for i in range(n):
	num2 = (t - sdi[i][0]) // sdi[i][1] + int((t - sdi[i][0]) % sdi[i][1] != 0)
	num2 = max(num2, 0)
	num = sdi[i][0] + num2 * sdi[i][1]
	if num < time:
		ans = i + 1
		time = num
print(ans)


(a, b) = map(int, input().split())
s = 1000000000000
from math import ceil as e
p = 0
for i in range(1, a + 1):
	(c, d) = map(int, input().split())
	if b == c:
		exit(print(i))
	if c > b:
		if c < s:
			s = c
			p = i
	else:
		f = e(abs(b - c) / d) * d
		if s >= c + f:
			p = i
			s = c + f
print(p)


(n, t) = map(int, input().split())
res = {}
for i in range(1, n + 1):
	(s, d) = map(int, input().split())
	res[(s - t) % (s, d)[s < t]] = i
print(res[min(res)])


(n, t) = map(int, input().split())
sd = []
for i in range(n):
	(s, d) = map(int, input().split())
	sd.append((s, d, i + 1))
buses = (1000000.0, 1000000.0)
for i in sd:
	(s, d, bus) = i
	if s < t:
		if (t - s) % d == 0:
			print(bus)
			exit()
		elif buses[0] > s + ((t - s) // d + 1) * d:
			buses = (s + ((t - s) // d + 1) * d, bus)
	elif s == t:
		print(bus)
		exit()
	elif buses[0] > s > t:
		buses = (s, bus)
print(buses[1])


import math
x_ = [int(x) for x in input().split()]
(n, t) = (x_[0], x_[1])
res = []
for i in range(n):
	x_ = [int(x) for x in input().split()]
	(x, y) = (x_[0], x_[1])
	n_ = (t - x) / y + 1
	n_ = math.ceil(n_)
	v = x + (n_ - 1) * y
	if n_ >= 1 and v >= t:
		res.append((v, i + 1))
	if x >= t:
		res.append((x, i + 1))
res.sort()
if len(res):
	print(res[0][1])


R = lambda : map(int, input().split())
(n, t) = R()
v = []
for i in range(n):
	(x, y) = R()
	if x < t:
		x = x + (t - x + y - 1) // y * y
	v += (x - t,)
print(v.index(min(v)) + 1)


import math
(n, a) = map(int, input().split())
f = 0
ck = 9999999
for i in range(1, n + 1):
	(x, y) = map(int, input().split())
	if a == x:
		ans = i
		f = 2
	elif f != 2:
		if x < a:
			t = abs(x - a)
			t = math.ceil(t / y)
			t = t * y
			t = x + t
			if t < ck:
				ck = t
				ans = i
		elif x < ck:
			ck = x
			ans = i
print(ans)


import math
(n, t) = [int(x) for x in input().split()]
routes = []
for i in range(0, n):
	a = [int(x) for x in input().split()]
	routes.append(a)
counter = []
for m in range(0, n):
	element = routes[m]
	if element[0] >= t:
		counter.append(element[0])
	else:
		limit = math.ceil((t - element[0]) / element[1]) * element[1] + element[0]
		counter.append(limit)
print(counter.index(min(counter)) + 1)


import math
(n, t) = map(int, input().split())
min_wait = 1000000
idx = -1
for i in range(n):
	(s, d) = map(int, input().split())
	if s > t:
		wait = s - t
	else:
		wait = s + d * math.ceil((t - s) / d) - t
	if wait < min_wait:
		min_wait = wait
		idx = i + 1
print(idx)


import math
(n, t) = list(map(int, input().split()))
mx = 10 ** 8
mxi = -1
for i in range(n):
	(s, d) = list(map(int, input().split()))
	if s >= t:
		firstb = s
	else:
		tt = t - s
		dd = d * math.ceil(tt / d)
		firstb = dd + s
	if firstb < mx:
		mx = firstb
		mxi = i + 1
print(mxi)


mod = 10 ** 9 + 7
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, t) = f()
l1 = []
l2 = []
for i in range(n):
	(a, b) = f()
	l1.append(a - t)
	l2.append(b)
for i in range(n):
	if l1[i] < 0:
		l1[i] += abs(l1[i] // l2[i]) * l2[i]
print(l1.index(min(l1)) + 1)


from math import ceil
nt = input().split()
n = int(nt[0])
t = int(nt[1])
bus = []
for nn in range(n):
	sd = input().split()
	s = int(sd[0])
	d = int(sd[1])
	if t <= s:
		bus.append(s)
	else:
		k = int((t - s) / d)
		if k < (t - s) / d:
			k += 1
		temp = s + k * d
		bus.append(temp)
bust = bus[:]
bust.sort()
choose = bust[0]
print(bus.index(choose) + 1)


(n, t) = list(map(int, input().strip().split()))
times = []
interval = []
l = 0
for i in range(n):
	(x, y) = list(map(int, input().strip().split()))
	times.append(x)
	interval.append(y)
	l += 1
try:
	print(times.index(t) + 1)
except ValueError:
	min_time = 1000000
	for i in range(l):
		if times[i] < t:
			x = (t - times[i]) / interval[i]
			if not x.is_integer():
				x = int(x) + 1
			else:
				x = int(x)
			if times[i] + x * interval[i] < min_time:
				min_time = times[i] + x * interval[i]
				index = i
		elif times[i] < min_time:
			min_time = times[i]
			index = i
	print(index + 1)


import string, copy

def _helper(t, s, r):
	ans = s
	while ans < t:
		ans += r
	return ans

def solution(buses, t):
	times = []
	for (s, r) in buses:
		times.append(_helper(t, s, r))
	m = min(times)
	return times.index(m) + 1

def parser():
	(n, t) = [int(i) for i in input().split(' ')]
	buses = []
	for _ in range(n):
		buses.append([int(i) for i in input().split(' ')])
	return (buses, t)

def output(s):
	print(s)

def main():
	args = parser()
	result = solution(*args)
	output(result)
main()


import math

def distance(a, b):
	return abs(a - b)
(n, t) = tuple(map(int, input().split()))
(s, d) = ([], [])
for i in range(n):
	arr = list(map(int, input().split()))
	s.append(arr[0])
	d.append(arr[1])
if t in s:
	idx = s.index(t)
	print(idx + 1)
else:
	time = []
	count = 0
	for k in range(n):
		tmp = math.ceil((t - s[k]) / d[k])
		if tmp >= 0:
			time.append(s[k] + tmp * d[k] - t)
		else:
			time.append(s[k] - t)
			count += 1
	idx = time.index(min(time))
	print(idx + 1)


import math
(n, t) = map(int, input().split())
ride = []
buses = []
for i in range(n):
	(s, d) = map(int, input().split())
	if s < t:
		a = math.ceil((t - s) / d)
		bus = s + d * a
		buses.append((bus, i + 1))
	else:
		buses.append((s, i + 1))
buses.sort()
print(buses[0][1])


(n, t) = map(int, input().split())
res = {}
for i in range(1, n + 1):
	(s, d) = map(int, input().split())
	res.setdefault((s - t) % d if s < t else s - t, i)
print(res[min(res)])


import io, os
input = io.StringIO(os.read(0, os.fstat(0).st_size).decode()).readline
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
(n, t) = mi()
mn = 10 ** 9
ans = None
b = [li() for i in range(n)]
for i in range(n):
	(s, d) = b[i]
	if s >= t:
		if s - t < mn:
			mn = s - t
			ans = i
	else:
		dif = t - s
		steps = (dif + d - 1) // d
		nxt = s + steps * d
		if nxt - t < mn:
			mn = nxt - t
			ans = i
print(ans + 1)


(n, t) = map(int, input().split())
m = 100000
k = 0
for i in range(n):
	(s, d) = map(int, input().split())
	if t <= s:
		if s - t < m:
			m = s - t
			k = i + 1
	else:
		x = (t - s) // d
		if (t - s) % d != 0:
			x += 1
		if d * x + s - t < m:
			m = d * x + s - t
			k = i + 1
print(k)


import math
(n, t) = map(int, input().split())
tmin = 2 * 10 ** 5
ans = 0
for i in range(n):
	(s, d) = map(int, input().split())
	cur = math.ceil(max(0, t - s) / d) * d + s
	if cur < tmin:
		tmin = cur
		ans = i + 1
print(ans)


import math
(n, t) = list(map(int, input().split()))
matrix = [list(map(int, input().split())) for _ in range(n)]

def calc_xi(s, d):
	if t < s:
		return s
	u = math.ceil((t - s) / d)
	return s + u * d
xis = [calc_xi(s, d) for [s, d] in matrix]
print(xis.index(min(xis)) + 1)


(n, t) = map(int, input().split())
inf = 1 << 60
ans = 0
wans = inf
for i in range(n):
	(s, d) = map(int, input().split())
	if t < s:
		w = s - t
	else:
		w = (t - s) % d
		if w != 0:
			w = d - w
	if wans > w:
		wans = w
		ans = i + 1
print(ans)


from math import ceil
(n, t) = map(int, input().split())
mi = 10 ** 10
for i in range(n):
	(s, d) = map(int, input().split())
	if t < s:
		ans = s
	else:
		ans = s + ceil((t - s) / d) * d
	if ans < mi:
		mi = ans
		ind = i + 1
print(ind)


import math
(n, m) = map(int, input().split())
l = []
for i in range(n):
	(x, y) = map(int, input().split())
	if m <= x:
		l.append(x - m)
	else:
		r = math.ceil((m - x) / y)
		x = x + y * r
		l.append(x - m)
k = min(l)
print(l.index(k) + 1)


(num, time) = map(int, input().split())
ans = []
val = []
for (index, x) in enumerate(range(num)):
	(first, in_between) = map(int, input().split())
	while first < time:
		first += in_between
	val.append(first - time)
	ans.append(index + 1)
mn = min(val)
print(ans[val.index(mn)])


def find_min(f, i, s, bus):
	check_arrival = f - s
	if check_arrival < 0:
		check_arrival = check_arrival % i
	return (check_arrival, bus)
[jumlah_bis, time_serval] = [int(x) for x in input().split(' ')]
list_bus = []
for i in range(jumlah_bis):
	[first_bus, interval_bus] = [int(x) for x in input().split(' ')]
	list_bus.append([first_bus, interval_bus])
minimum_list = []
for i in range(len(list_bus)):
	minimum = find_min(list_bus[i][0], list_bus[i][1], time_serval, i)
	minimum_list.append(minimum)
print(min(minimum_list)[1] + 1)


from sys import stdin, exit
import math
(n, t) = map(int, stdin.readline().split())
p = []
for i in range(n):
	(a, b) = map(int, stdin.readline().split())
	if a >= t:
		p.append(a - t)
	else:
		r = int(math.ceil((t - a) / b))
		p.append(a + r * b - t)
mini = p[0]
if n == 1:
	print(1)
else:
	poi = 1
	for i in range(1, len(p)):
		if p[i] < mini:
			mini = p[i]
			poi = i + 1
	print(poi)


from sys import stdin

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
from math import ceil
(n, t) = minput()
l = []
for i in range(1, n + 1):
	(s, d) = minput()
	l.append(s + max(0, ceil((t - s) / d)) * d - t)
print(l.index(min(l)) + 1)


(n, t) = map(int, input().split())
(res, result) = (1000000000000000000, 0)
for i in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		if res > s - t:
			(res, result) = (s - t, i + 1)
	else:
		mod = (t - s) % d
		if mod == 0:
			(res, result) = (0, i + 1)
		elif res > d - mod:
			(res, result) = (d - mod, i + 1)
print(result)


import math
arr = [int(x) for x in input().split()]
n = arr[0]
st = arr[1]
mini = 1000000
ans = 0
for i in range(n):
	arr = [int(x) for x in input().split()]
	si = arr[0]
	di = arr[1]
	if si > st:
		opt = si - st
	else:
		diff = st - si
		f = math.ceil(diff / di)
		opt = si + f * di - st
	if opt < mini:
		mini = opt
		ans = i
print(ans + 1)


(n, t) = map(int, input().split())
arr = []
for i in range(n):
	(a, b) = map(int, input().split())
	while a < t:
		a += b
	arr.append([a, i])
arr.sort()
print(arr[0][1] + 1)


(n, t) = map(int, input().split())
s = []
for __ in range(n):
	(a, b) = map(int, input().split())
	a -= t
	if a < 0:
		a = a % b
	s.append(a)
print(s.index(min(s)) + 1)


while True:
	try:
		(n, t) = map(int, input().strip().split())
		(m, r) = (-1, 0)
		for i in range(n):
			(s, d) = map(int, input().strip().split())
			if s >= t:
				w = s - t
			else:
				w = ((t - s) // d + 1) * d + s - t if (t - s) % d != 0 else 0
			if m < 0 or w < m:
				m = w
				r = i + 1
		print(r)
	except:
		break


(N, T) = [int(x) for x in input().split(' ')]
minT = []
for n in range(0, N):
	(s, d) = [int(x) for x in input().split(' ')]
	if s >= T:
		minT.append((s, n + 1))
		continue
	x = s + d
	while x < T:
		x += d
	s = (x, n + 1)
	minT.append(s)
minT.sort()
print(minT[0][1])


x = input().split()
n = int(x[0])
s = int(x[1])
lista = []
t = False
for i in range(n):
	x = input().split()
	a = int(x[0])
	b = int(x[1])
	if a > s:
		lista.append(a)
	elif a is s:
		print(i + 1)
		t = True
		break
	else:
		c = (s - a) // b
		if (s - a) % b != 0:
			c += 1
		lista.append(c * b + a)
minV = min(lista)
if not t:
	for i in range(len(lista)):
		if lista[i] is minV:
			print(i + 1)
			break


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import *
from itertools import *
import functools
import sys
import math
import random
import re
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 9

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN(x=' '):
	return map(int, sys.stdin.readline().strip().split(x))

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def dis(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def lgcd(a):
	g = a[0]
	for i in range(1, len(a)):
		g = math.gcd(g, a[i])
	return g

def ms(a):
	msf = -MAX
	meh = 0
	for i in range(len(a)):
		meh += a[i]
		if msf < meh:
			msf = meh
		if meh < 0:
			meh = 0
	return msf

def res(ans, t):
	print('Case #{}: {}'.format(t, ans))

def chk(x, t):
	a = x[0]
	d = x[1]
	n = math.ceil((t - a) / d + 1)
	return a + (n - 1) * d
(n, t) = numIN()
l = [0]
for _ in range(n):
	(a, b) = numIN()
	l.append([a, b])
a = [MAX]
for i in range(1, n + 1):
	if l[i][0] < t:
		a.append(chk(l[i], t))
	else:
		a.append(l[i][0])
print(a.index(min(a)))


(n, t) = [int(i) for i in input().split()]
sd = [[int(i) for i in input().split()] for j in range(n)]
res = -1
best = 10 ** 10
for i in range(n):
	(s, d) = sd[i]
	if t <= s:
		if s < best:
			best = s
			res = i
	else:
		left = t - s
		times = left // d
		if left % d != 0:
			times += 1
		s += d * times
		if s < best:
			best = s
			res = i
print(res + 1)


import math

def main():
	(n, t) = map(int, input().split())
	(ret, best_time) = (0, float('inf'))
	for i in range(n):
		(s, d) = map(int, input().split())
		if s < t:
			k = int(math.ceil((t - s) / d))
			s += k * d
		if s < best_time:
			ret = i + 1
			best_time = s
	print(ret)
main()


import math
lowest = 0
lowestTime = -1
(n, t) = map(int, input().split())
for i in range(0, n):
	(s, d) = map(int, input().split())
	if s < t:
		s = math.ceil((t - s) / d) * d + s
	if lowestTime == -1:
		lowestTime = s
		lowest = i
	elif s < lowestTime:
		lowest = i
		lowestTime = s
print(lowest + 1)


w = input()
l1 = w.split()
n = int(l1[0])
t = int(l1[1])
dct = {}
for i in range(n):
	a = input()
	l2 = a.split()
	s = int(l2[0])
	d = int(l2[1])
	k = s
	while k < t:
		k += d
	dct[i + 1] = k
x = dct.values()
m = min(x)
key = [key for (key, value) in dct.items() if value == m]
print(key[0])


import math
(n, t) = map(int, input().split())
best = None
dis = None
for i in range(n):
	(s, d) = map(int, input().split())
	if t > s:
		temp = math.ceil((t - s) / d)
		s = s + d * temp
	temp = s - t
	if dis == None:
		dis = temp
	if best == None:
		best = i + 1
	elif dis > temp:
		dis = temp
		best = i + 1
print(best)


from sys import stdin
input = stdin.readline
R = lambda : map(int, input().split())
(n, t) = R()
v = []
for i in range(n):
	(x, y) = R()
	if x < t:
		x = x + (t - x + y - 1) // y * y
	v += (x - t,)
print(v.index(min(v)) + 1)


v = input().split(' ')
t = int(v[1])
n = int(v[0])
ans = []
for i in range(0, n):
	a = input().split(' ')
	st = int(a[0])
	interval = int(a[1])
	if st >= t:
		ans.append([i, st])
	else:
		count = (t - st) / interval
		if count % 1 != 0:
			count = int(count + 1)
		ans.append([i, st + count * interval])

def f(a):
	return a[1]
print(min(ans, key=f)[0] + 1)


(n, t) = input().split()
t = int(t)
m = 9999999999
ind = 0
ch = 0
for i in range(int(n)):
	l = list(map(int, input().split()))
	x = l[0]
	while True:
		if x - t >= 0:
			if m > x - t:
				m = x - t
				ind = i + 1
			break
		x = x + l[1]
	if m == 0:
		print(ind)
		ch = 1
		break
if ch != 1:
	print(ind)


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def __next__(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = sys.stdin.readline().split()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_int(self):
		return int(next(self))

	def cal(self, s):
		if len(s) == 1:
			return s[0]
		if s[0] == 0:
			return self.cal(s[1:])
		v = 1
		for c in s:
			v *= c
		return v

	def solve(self):
		n = self.next_int()
		t = self.next_int()
		ii = 0
		tt = 10000000
		for i in range(0, n):
			fr = self.next_int()
			d = self.next_int()
			if fr < t:
				fr += (t - fr + d - 1) // d * d
			if fr < tt:
				tt = fr
				ii = i
		print(ii + 1)

def __starting_point():
	Main().solve()
__starting_point()


(n, t) = list(map(int, input().split(' ')))

def ceil(z):
	if z <= 0:
		return 0
	if int(z) == z:
		return int(z)
	else:
		return int(z) + 1
l = []
for _ in range(n):
	(s, d) = list(map(int, input().split(' ')))
	k = ceil((t - s) / d)
	x = s + k * d
	l.append(x)
i = 0
mi = l[0]
for (ii, x) in enumerate(l):
	if x < mi:
		mi = x
		i = ii
print(i + 1)


(n, t) = map(int, input().split())
res = [float('inf'), 0]
for i in range(1, n + 1):
	(s, d) = map(int, input().split())
	x = max((t - s + d - 1) // d, 0)
	v = s + d * x
	if res[0] > v:
		res = [v, i]
print(res[1])


cnt = []
(n, t) = list(map(int, input().split()))
for i in range(n):
	(a, b) = list(map(int, input().split()))
	if t < a:
		cnt.append([a, i])
	elif (t - a) % b == 0:
		cnt.append([t, i])
	else:
		cnt.append([t + b - (t - a) % b, i])
cnt.sort()
print(cnt[0][1] + 1)


(n, t) = map(int, input().split())
mini = 1
mint = 10 ** 9 + 1
for i in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		time = s
	else:
		y = (t - s + d - 1) // d
		time = s + y * d
	if time < mint:
		mint = time
		mini = i + 1
print(mini)


arr = input().split()
n = int(arr[0])
t = int(arr[1])
new = dict()
for i in range(n):
	arr1 = input().split()
	val = int(arr1[0])
	val1 = int(arr1[1])
	if val <= t:
		diff = (t - val) % val1
		if diff == 0:
			new[diff] = int(i) + 1
		else:
			new[val1 - diff] = int(i) + 1
	else:
		diff = val - t
		new[diff] = int(i) + 1
mini = 100000000000000000
ans = 0
for (k, v) in new.items():
	if k < mini:
		mini = k
		ans = v
print(ans)


(n, t) = map(int, input().split())
imin = 0
wait_min = None
for i in range(n):
	(s, d) = map(int, input().split())
	if t < s:
		w = s - t
	else:
		w = d - (t - s) % d
		if w == d:
			w = 0
	if wait_min is None or w < wait_min:
		wait_min = w
		imin = i
print(imin + 1)


(n, t) = map(int, input().split())
arr = []
temp = []
for _ in range(n):
	(first, interval) = map(int, input().split())
	arr.append((first, interval))
	temp.append(first + interval)
temp.sort()
mini = []
for i in range(n):
	j = 0
	while arr[i][0] + j * arr[i][1] - t <= temp[-1]:
		if arr[i][0] + j * arr[i][1] - t >= 0:
			mini.append(arr[i][0] + j * arr[i][1] - t)
			break
		j += 1
index = 0
minimum = mini[0]
for i in range(1, len(mini)):
	if mini[i] < minimum:
		minimum = mini[i]
		index = i
print(index + 1)


import sys
(n, t) = map(int, input().split())
k = []
for i in range(n):
	(a, b) = map(int, input().split())
	a -= t
	if a < 0:
		a %= b
	k.append(a)
print(k.index(min(k)) + 1)


from math import ceil
(n, k) = map(int, input().split())
dict = {}
for i in range(n):
	(s, d) = map(int, input().split())
	dict[i + 1] = s + d * max(0, ceil((k - s) / d))
ls = dict.values()
m = min(ls)
for (k, v) in dict.items():
	if v == m:
		print(k)
		break


import sys
(n, t) = map(int, input().split())
j = 1
mi = sys.maxsize
mij = j
for i in range(n):
	(s, d) = map(int, input().split())
	p = (t - s) // d + (1 if (t - s) % d > 0 else 0)
	k = s + p * d
	if p < 0:
		k = s
	if mi > k - t:
		mij = j
		mi = k - t
	j += 1
print(mij)


(n, t) = map(int, input().split())
s = [0] * n
d = [0] * n
for i in range(n):
	(s[i], d[i]) = map(int, input().split())
diff = [0] * n
for i in range(n):
	diff[i] = s[i] - t
for i in range(n):
	c = t - s[i]
	if c > 0:
		k = c // d[i]
		if k * d[i] != c:
			k += 1
		diff[i] = k * d[i] + s[i] - t
print(diff.index(min(diff)) + 1)


import sys
import math
fn = list(map(int, input().split()))
mc = 10 ** 5
mn = 10 ** 9
br = 0
bt = 0
for n in range(1, fn[0] + 1):
	an = list(map(int, input().split()))
	if an[0] == fn[1]:
		print(n)
		sys.exit()
	elif an[0] > fn[1]:
		bt = n
		if an[0] < mn:
			mn = an[0]
			br = n
	else:
		if an[1] == 1:
			print(n)
			sys.exit()
		a = int(math.ceil((fn[1] - an[0]) / an[1])) * an[1] + an[0]
		if a == fn[1]:
			print(n)
			sys.exit()
		elif a < mn:
			mn = a
			br = n
if br == 0:
	if bt == 0:
		print(0)
	else:
		print(bt)
	sys.exit()
print(br)


cin = input().split()
(n, t) = (int(cin[0]), int(cin[1]))
res = 10 ** 6
for i in range(n):
	cin = input().split()
	(s, d) = (int(cin[0]), int(cin[1]))
	temp_res = s
	if s < t:
		temp = d - (t - s) % d
		if temp == d:
			temp = 0
		temp_res = t + temp
	if temp_res < res:
		res = temp_res
		ans = i + 1
print(ans)


import sys, math
(n, t) = [int(x) for x in input().split()]
o = []
for i in range(n):
	(s, d) = [int(x) for x in input().split()]
	if s == t:
		print(i + 1)
		sys.exit()
	if s < t:
		o.append(s + math.ceil((t - s) / d) * d)
	else:
		o.append(s)
m = min(o)
print(o.index(m) + 1)


import math
(n, t) = [int(i) for i in input().split()]
mmin = 0
for i in range(n):
	[s, d] = [int(i) for i in input().split()]
	if s == t:
		print(i + 1)
		exit()
	if s > t:
		m = s
	else:
		m = math.ceil(1.0 * (t - s) / d) * d + s
	if mmin == 0 or m < mmin:
		(mmin, imin) = (m, i)
print(imin + 1)


from math import ceil
(n, t) = map(int, input().split())
l = []
for i in range(n):
	(x, y) = map(int, input().split())
	if t <= x:
		l.append(x)
	else:
		z = ceil((t - x) / y)
		l.append(x + z * y)
print(l.index(min(l)) + 1)


line1 = input()
busRoutes = int(line1.split()[0])
startTime = int(line1.split()[1])
arrivals = []
intervals = []
for x in range(busRoutes):
	line = input()
	arrival = int(line.split()[0])
	interval = int(line.split()[1])
	if arrival in arrivals and interval in intervals:
		arrivals.append(0)
		intervals.append(0)
	else:
		arrivals.append(arrival)
		intervals.append(interval)
selectedBus = 0
time = startTime
countNonZero = 0
for i in range(len(arrivals)):
	if not (arrivals[i] == 0 and intervals[i] == 0):
		countNonZero += 1
	if countNonZero >= 2:
		break
if countNonZero == 1:
	selectedBus = 1
while selectedBus == 0:
	for i in range(len(arrivals)):
		if arrivals[i] == 0 and intervals[i] == 0:
			continue
		while arrivals[i] < time:
			arrivals[i] = arrivals[i] + intervals[i]
		if arrivals[i] != time:
			continue
		selectedBus = i + 1
		break
	if selectedBus == 0:
		minimum = 0
		for i in range(len(arrivals)):
			if minimum == 0 and arrivals[i] > 0:
				minimum = arrivals[i]
			elif arrivals[i] > 0 and arrivals[i] < minimum:
				minimum = arrivals[i]
		time = minimum
print(selectedBus)


from math import ceil
(n, t) = map(int, input().split())
first_bus = float('inf')
route = 0
for i in range(n):
	(s, d) = map(int, input().split())
	if s < t:
		s += d * ((t - s) // d)
		while s < t:
			s += d
	if first_bus > s:
		first_bus = s
		route = i + 1
print(route)


from math import sqrt, ceil, floor
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
import string
import bisect
(n, t) = list(map(int, stdin.readline().split()))
ans = 1
ans_t = 9999999
for i in range(n):
	(s, d) = list(map(int, stdin.readline().split()))
	if s < t:
		s = s + ceil((t - s) / d) * d
	if ans_t > s:
		ans = i + 1
		ans_t = s
print(ans)


read = lambda : list(map(int, input().split(' ')))
n_t = read()
(n, t) = n_t
ans = 1
dist = 10 ** 5
for i in range(n):
	s_d = read()
	(s, d) = s_d
	if s == t:
		ans = i + 1
		dist = 0
	elif s > t:
		if s - t < dist:
			ans = i + 1
			dist = s - t
	else:
		if (t - s) % d == 0:
			s += d * ((t - s) // d)
		else:
			s += d * ((t - s) // d + 1)
		if s - t < dist:
			ans = i + 1
			dist = s - t
print(ans)


(n, a) = map(int, input().split())
s = []
d = []
for i in range(n):
	(x, y) = map(int, input().split())
	s.append(x)
	d.append(y)
for i in range(n):
	if s[i] < a:
		x = a - s[i]
		if s[i] + d[i] * (x // d[i]) >= a:
			s[i] = s[i] + d[i] * (x // d[i])
		else:
			s[i] = s[i] + d[i] * (x // d[i] + 1)
mn = 1000000
ans = 0
for i in range(n):
	if s[i] < mn and s[i] >= a:
		mn = s[i]
		ans = i
print(ans + 1)


(n, t) = map(int, input().split())
mi = 10 ** 10
for i in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		s = s - t
	else:
		s = (t - s) % d
		if s != 0:
			s = d - s
	if mi > s:
		mi = s
		id = i + 1
print(id)


(N, T) = [int(s) for s in input().split()]
closest_T = None
closest_i = None
for i in range(N):
	(s, d) = [int(s) for s in input().split()]
	n = max(0, T - s) // d + int(max(0, T - s) % d > 0)
	time = s + n * d
	if closest_T is None or time < closest_T:
		closest_T = time
		closest_i = i + 1
print(closest_i)


(n, t) = list(map(int, input().split()))
options = {}
for route in range(n):
	(s, d) = list(map(int, input().split()))
	if s < t:
		if t >= d:
			s += int(t / d) * d
			while s - d >= t:
				s -= d
			while s < t:
				s += d
		else:
			s += d
	options[s] = route + 1
print(options.get(min(options)))


import math
a = []
(n, t) = map(int, input().split())
for i in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		a.append(s)
	else:
		l = math.ceil((t - s) / d)
		a.append(s + d * l)
m = min(a)
for i in range(n):
	if a[i] == m:
		ans = i + 1
		break
print(ans)


(n, t) = [int(x) for x in input().split()]
a = []
f = False
i = 1
r = 0
for x in range(n):
	(Di, Si) = [int(x) for x in input().split()]
	while Di < t and f == False:
		Di += Si
		pass
	a.append(Di)
	time = Di
	if time == t and f == False:
		r = i
		f = True
		pass
	i += 1
	pass

def getRout(A):
	minT = 0
	R = 0
	I = 1
	for x in A:
		if minT == 0 or x < minT:
			minT = x
			R = I
			pass
		I += 1
	pass
	return R
if f:
	print(r)
else:
	print(getRout(a))


(n, t) = [int(i) for i in input().split(' ')]
buses = [[int(i) for i in input().split(' ')] for _ in range(n)]
m = -1
res = -1
his = dict()
for (i, b) in enumerate(buses):
	tt = b[0]
	if not his.get((b[0], b[1])):
		while tt < t:
			tt += b[1]
		his[b[0], b[1]] = tt
	else:
		tt = his[b[0], b[1]]
	if tt < m or m == -1:
		m = tt
		res = i + 1
print(res)


import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque, Counter
from math import gcd, sqrt, factorial, ceil, log10, log2
from itertools import permutations
from heapq import heappush, heappop, heapify
inf = float('inf')
mod = 1000000007

def factorial_p(n, p):
	ans = 1
	if n <= p // 2:
		for i in range(1, n + 1):
			ans = ans * i % p
	else:
		for i in range(1, p - n):
			ans = ans * i % p
		ans = pow(ans, p - 2, p)
		if n % 2 == 0:
			ans = p - ans
	return ans

def nCr_p(n, r, p):
	ans = 1
	while n != 0 or r != 0:
		(a, b) = (n % p, r % p)
		if a < b:
			return 0
		ans = ans * factorial_p(a, p) * pow(factorial_p(b, p), p - 2, p) * pow(factorial_p(a - b, p), p - 2, p) % p
		n //= p
		r //= p
	return ans

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def binary(number):
	result = 0
	while number:
		result = result + 1
		number = number & number - 1
	return result

def is_prime(n):
	if n < 5 or n & 1 == 0 or n % 3 == 0:
		return 2 <= n <= 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			p = p * p % n
			if p == n - 1:
				break
		else:
			return False
	return True

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
(n, t) = get_ints()
temp = []
for i in range(n):
	(s, d) = get_ints()
	s -= t
	if s < 0:
		s = s % d
	temp.append(s)
print(temp.index(min(temp)) + 1)


import math
(routes, time) = [int(x) for x in input().split()]
bestT = 1000000000
bestR = 0
for i in range(routes):
	(start, interval) = [int(x) for x in input().split()]
	mult = math.ceil((time - start) / interval)
	btime = 0
	if mult <= 0:
		btime = start
	else:
		btime = start + interval * mult
	calc = btime - time
	if calc < bestT:
		bestT = calc
		bestR = i + 1
print(bestR)


(n, T) = map(int, input().split())
num = float('inf')
ans = -1
for i in range(n):
	(s, t) = map(int, input().split())
	if T <= s:
		if num > s:
			num = s
			ans = i + 1
	else:
		a = T - s
		b = a // t + int(a % t != 0)
		tmp = s + t * b
		if tmp < num:
			num = tmp
			ans = i + 1
print(ans)


def get(s, d, t):
	if t <= s:
		return s
	ans = (t - s) // d
	if (t - s) % d:
		ans += 1
	return ans * d + s
(n, t) = map(int, input().split())
l = []
for i in range(n):
	(s, d) = map(int, input().split())
	l.append([get(s, d, t), i])
l.sort(key=lambda x: x[0])
print(l[0][1] + 1)


import sys
import math
(n, t) = list(map(int, input().split()))
arr = []
mn = 1000000009
for i in range(n):
	arr.append(list(map(int, input().split())))
pos = 1
for i in range(n):
	val = arr[i][0]
	if val == t or val + arr[i][1] == t:
		print(i + 1)
		sys.exit()
	div = arr[i][0]
	if arr[i][0] < t:
		div = t - arr[i][0]
		div = math.ceil(div / arr[i][1])
		div = div * arr[i][1]
		div = div + arr[i][0]
	if mn > div:
		mn = div
		pos = i + 1
print(pos)


import sys
(n, t) = map(int, input().split())
fans = sys.maxsize
for z in range(n):
	(s, d) = map(int, input().split())
	x = 0
	y = 0
	if s == t:
		ans = s
	elif s < t:
		t = t - s
		x = t // d
		x = x * d + s
		y = t // d + 1
		y = y * d + s
		t = t + s
		if x >= t:
			ans = x
		elif y >= t:
			ans = y
	else:
		ans = s
	if fans > ans:
		fasoos = z + 1
		fans = ans
print(fasoos)


(n, t) = map(int, input().strip().split())
globMin = 99999999999
route = 1
for i in range(n):
	(s, d) = map(int, input().strip().split())
	vals = [s] + [i for i in range(s + d, t + d + 1, d)]
	mini = 9999999999
	for j in vals:
		if j >= t:
			mini = min(j - t, mini)
	if mini < globMin:
		globMin = mini
		route = i + 1
print(route)


import math
(nr, at) = map(int, input().split())
ls = []
for _ in range(nr):
	(st, inter) = map(int, input().split())
	if st >= at:
		ls.append(st)
		continue
	space = math.ceil((at - st) / inter)
	st += space * inter
	ls.append(st)
print(ls.index(min(ls)) + 1)


from math import *
(n, t) = map(int, input().split())
arr = []
diff = 10000000
ans = -1
for i in range(n):
	(s, d) = map(int, input().split())
	if s > t:
		if s - t < diff:
			ans = i + 1
			diff = s - t
	else:
		val = ceil((t - s) / d)
		time = s + val * d
		if time - t < diff:
			ans = i + 1
			diff = time - t
print(ans)


from math import ceil
(n, t) = map(int, input().split())
bus = []
for _ in range(n):
	(s, d) = map(int, input().split())
	if t <= s:
		bus.append(s)
	else:
		z = ceil((t - s) / d)
		bus.append(s + z * d)
print(bus.index(min(bus)) + 1)


(n, t) = map(int, input().split())
r = []
for i in range(n):
	(a, b) = map(int, input().split())
	if t - a > 0:
		if (t - a) % b == 0:
			r.append(0)
		else:
			r.append(b - (t - a) % b)
	else:
		r.append(a - t)
m = min(r)
for i in range(n):
	if r[i] == m:
		print(i + 1)
		break


(n, time) = (int(i) for i in input().split())
l = []
for i in range(n):
	(a, b) = (int(i) for i in input().split())
	m = time - a
	if m > 0:
		if m % b == 0:
			l.append(0)
		elif m > 0:
			l.append(abs(m - (m // b + 1) * b))
		else:
			l.append(abs(m))
	else:
		l.append(abs(m))
print(l.index(min(l)) + 1)


from sys import stdin, stdout
(n, t) = map(int, input().split())
time = 1000000
busroute = 0
import math
for i in range(n):
	(x, y) = map(int, input().split())
	if t <= x:
		curr = x
	else:
		curr = math.ceil((t - x) / y) * y + x
	if curr < time:
		time = curr
		busroute = i + 1
print(busroute)


(n, t) = [int(i) for i in input().split()]
(mn, ans) = (0, 0)
for x in range(n):
	(s, d) = [int(i) for i in input().split()]
	if s >= t:
		time = s - t
	else:
		time = ((t - s - 1) // d + 1) * d + s - t
	if ans == 0:
		ans = x + 1
		mn = time
	elif time < mn:
		mn = time
		ans = x + 1
print(ans)


(n, t) = map(int, input().split())
data = [[int(i) for i in input().split()] for _ in range(n)]
bestT = []
for i in range(n):
	if data[i][0] >= t:
		bestT.append(data[i][0])
	else:
		k = (t - data[i][0]) // data[i][1]
		tt = data[i][0] + k * data[i][1]
		if t <= tt:
			bestT.append(tt)
		elif tt + data[i][1] >= t:
			bestT.append(tt + data[i][1])
		else:
			bestT.append(tt + 2 * data[i][1])
print(bestT.index(min(bestT)) + 1)


(n, t) = map(int, input().split())
minx = [10 ** 10, 0]
for i in range(n):
	(start, inter) = map(int, input().split())
	(l, r) = (-1, 10 ** 5)
	while r - l > 1:
		m = (l + r) // 2
		if start + inter * m >= t:
			r = m
		else:
			l = m
	if start + inter * r < minx[0]:
		minx[0] = start + inter * r
		minx[1] = i + 1
print(minx[1])


(n, t) = [int(x) for x in input().split()]
a = []
for x in range(n):
	(Di, Si) = [int(x) for x in input().split()]
	a.append([Di, Si])
	pass

def getRout(A):
	rout = 0
	sumN = 0
	i = 1
	for x in A:
		time = x[0]
		while time < t:
			time += x[1]
			pass
		if time == t:
			rout = i
			break
			pass
		if time < sumN or (sumN == 0 and time != sumN):
			sumN = time
			rout = i
		i += 1
	pass
	return rout
print(getRout(a))


aa = [int(x) for x in input().split()]
n = aa[1]
ile = aa[0]

def check():
	d = []
	s = []
	for i in range(ile):
		t = [int(x) for x in input().split()]
		d += [t[0]]
		s += [t[1]]
	for i in range(len(d)):
		while d[i] < n:
			d[i] += s[i]
		if d[i] == n:
			print(i + 1)
			return
	mm = min(d)
	for i in range(len(d)):
		if d[i] == mm:
			print(i + 1)
			return
check()


import math
(n, t) = map(int, input().split())
ires = 0
tres = 10000000
for i in range(1, n + 1):
	(s, d) = map(int, input().split())
	if t >= s:
		k = math.ceil(1.0 * (t - s) / d)
	else:
		k = 0
	tcur = s + d * k
	if t <= tcur < tres:
		ires = i
		tres = tcur
print(ires)


import math
M = lambda : list(map(int, input().strip().split()))
(n, t) = M()
best = float('inf')
best_bus = None
for i in range(1, n + 1):
	(s, d) = M()
	curr = math.ceil((t - s) / d) * d + s if t > s else s
	if curr == t:
		best_bus = i
		break
	if best > curr:
		best_bus = i
		best = curr
print(best_bus)


from math import ceil
[n, a] = [int(n) for n in input().split(' ')]
index = -1
mit_t = 0
for i in range(1, n + 1):
	[s, d] = [int(n) for n in input().split(' ')]
	diff = a - s
	bus_i = ceil(diff / d) if diff > 0 else 0
	t = s + bus_i * d
	if index < 0 or t < min_t:
		index = i
		min_t = t
print(index)


(n, t) = map(int, input().split())
at = float('inf')
ans = -1
for i in range(1, n + 1):
	(s, d) = map(int, input().split())
	st = s if s >= t else (t + d - 1 - s) // d * d + s
	if st < at:
		at = st
		ans = i
print(ans)


(N, T) = map(int, input().split())
S = [0] * N
D = [0] * N
x = 0
ans = 0
X = 100000000000
m = 0
for i in range(0, N):
	(S[i], D[i]) = map(int, input().split())
for i in range(0, N):
	if S[i] >= T:
		if X > S[i]:
			X = S[i]
			ans = i + 1
	else:
		x = T - S[i]
		if x % D[i] == 0:
			x = x // D[i]
		else:
			x = x // D[i] + 1
		m = S[i] + x * D[i]
		if X > m:
			X = m
			ans = i + 1
print(ans)


nt = [int(c) for c in input().split()]
s = []
kq = []
for i in range(nt[0]):
	s.append([int(c) for c in input().split()])
for i in range(nt[0]):
	if s[i][0] < nt[1]:
		c = (nt[1] - s[i][0]) / s[i][1]
		if c > int(c):
			s[i][0] = s[i][0] + (int(c) + 1) * s[i][1]
		else:
			s[i][0] = s[i][0] + c * s[i][1]
	kq.append(s[i][0] - nt[1])
print(kq.index(min(kq)) + 1)


import math
(n, t) = list(map(int, input().strip().split()))
a = []
b = []
c = []
for i in range(n):
	a.append(list(map(int, input().strip().split())))
	if t <= a[i][0]:
		b.append(a[i][0])
	else:
		d = math.ceil((t - a[i][0]) / a[i][1])
		b.append(a[i][0] + d * a[i][1])
	c.append([b[i], i + 1])
print(min(c)[1])


(n, t) = map(int, input().split())
bus = []
for i in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		bus.append(s)
	else:
		temp = (t - s) // d * d + s
		if temp < t:
			temp = temp + d
		if t // d == 0:
			temp = s + d
		bus.append(temp)
x = bus.index(min(bus))
print(x + 1)


import sys

def ints():
	return list(map(int, sys.stdin.readline().strip().split()))
tc = 1
while tc:
	tc -= 1
	ans = 99999999999999
	ith = 99999999999999
	(n, t) = map(int, input().split())
	for i in range(n):
		(a, b) = map(int, input().split())
		if a >= t and ans > a:
			ans = a
			ith = i
		elif a < t:
			val = t - a
			new = val / b
			if new == int(new):
				new = int(new)
			else:
				new = int(new) + 1
			if a + b * new < ans:
				ans = a + b * new
				ith = i
	print(ith + 1)


(n, t) = [int(i) for i in input().split()]
bus = [0] * 100005
lrbn = -1
lrbt = -1
for i in range(n):
	(s, d) = [int(i) for i in input().split()]
	while s < 100005:
		bus[s] = i + 1
		s += d
	if lrbt == -1 or lrbt > s:
		lrbt = s
		lebn = i + 1
if bus[t] != 0:
	print(bus[t])
else:
	while t < 100005 and bus[t] == 0:
		t += 1
	if t < 100005 and bus[t] != 0:
		print(bus[t])
	else:
		print(lebn)


import math
(n, t) = map(int, input().split())
ans = float('inf')
min = float('inf')
for i in range(0, n):
	(a, d) = map(int, input().split())
	if t - a < 0 and a < min:
		min = a
		ans = i + 1
	elif t - a >= 0 and a + d * math.ceil((t - a) / d) < min:
		min = a + d * math.ceil((t - a) / d)
		ans = i + 1
print(ans)


for _ in range(1):
	(n, t) = map(int, input().split())
	arr = []
	for i in range(n):
		(s, d) = map(int, input().split())
		while s < t:
			s += d
		if s == t:
			print(i + 1)
			exit()
		arr.append(s)
	mn = 10 ** 9 + 7
	indx = -1
	for i in range(n):
		if mn > arr[i] - t:
			mn = arr[i] - t
			indx = i
		if mn == 0:
			break
	print(indx + 1)


import sys
import math
(n, t) = [int(x) for x in input().split()]
earliestdeparture = 9999999
bestbus = -1
for i in range(n):
	(first, interval) = [int(x) for x in input().split()]
	if first >= t:
		departure = first
	else:
		r = math.ceil((t - first) / interval)
		departure = first + r * interval
	if departure < earliestdeparture:
		bestbus = i + 1
		earliestdeparture = departure
print(bestbus)


import math
nt = list(map(int, input().split()))
n = nt[0]
t = nt[1]
min_dist = -1
result = 0
for i in range(n):
	sd = list(map(int, input().split()))
	s = sd[0]
	d = sd[1]
	temp = math.ceil((t - s) / d)
	if temp < 0:
		temp = 0
	if min_dist == -1 or min_dist > temp * d + s - t:
		result = i + 1
		min_dist = temp * d + s - t
print(result)


(n, t) = map(int, input().split())
pos = 0
minn = 10 ** 6
for i in range(n):
	(s, d) = map(int, input().split())
	if s == t:
		print(i + 1)
		exit(0)
	elif s > t:
		if s - t < minn:
			minn = s - t
			pos = i + 1
	elif d == 1:
		pos = i + 1
	elif (s - t) % d < minn:
		minn = (s - t) % d
		pos = i + 1
print(pos)


import math
(n, t) = map(int, input().split())
a = []
b = []
for _ in range(n):
	s = input().split()
	a.append(int(s[0]))
	b.append(int(s[1]))
route = 0
minn = 1000000
for i in range(0, n):
	if a[i] < t:
		a[i] += math.ceil((t - a[i]) / b[i]) * b[i]
for i in range(0, n):
	if a[i] < minn and a[i] >= t:
		minn = a[i]
		route = i
print(route + 1)


import math
(n, t) = map(int, input().split())
index = 0
m = float('inf')
for i in range(1, n + 1):
	(s, d) = map(int, input().split())
	tmp = float('inf')
	x = t - s
	if x == 0:
		index = i
		break
	elif x > 0:
		y = math.ceil(x / d)
		tmp = y * d - x
	else:
		tmp = -x
	if m > tmp:
		m = tmp
		index = i
print(index)


(n, t) = map(int, input().split())
(p, k) = (-1, 10 ** 18)
for i in range(n):
	(a, b) = map(int, input().split())
	if a < t:
		a += (t - a + b - 1) // b * b
	if a < k:
		k = a
		p = i
print(p + 1)


(n, t) = map(int, input().split(' '))
a = float('inf')
b = 0
for i in range(n):
	(s, d) = map(int, input().split(' '))
	if s >= t:
		x = s
	else:
		y = (t - s) % d
		if y == 0:
			z = (t - s) // d
		else:
			z = (t - s) // d + 1
		x = s + z * d
	if a > x:
		a = x
		b = i + 1
print(b)


def min_time_for_route(t, s, d):
	while s < t:
		s += d
	return s - t

def main():
	(n, t) = input().split()
	(n, t) = [int(n), int(t)]
	best_time = 10 ** 5
	for i in range(n):
		(s, d) = input().split()
		(s, d) = [int(s), int(d)]
		route_time = min_time_for_route(t, s, d)
		if route_time < best_time:
			best_route = i + 1
			best_time = route_time
	print(best_route)
main()


from math import ceil
(x, y) = map(int, input().split())
t = []
min1 = float('inf')
for i in range(x):
	l = list(map(int, input().split()))
	if l[0] < y:
		k = (y - l[0]) / l[1]
		k = l[0] + l[1] * ceil(k)
	else:
		k = l[0]
	min1 = min(k, min1)
	if k == min1:
		r = i + 1
print(r)


def main(argc, argv) -> {}:
	sync_with_stdio(false)
	cin.tie(0)
	cout.tie(0)
	n = 0
	n <<= cin
	t = 0
	t <<= cin
	besta = 1000001
	best_i = -1
	i = 0
	while i < n or {}:
		s = 0
		d = 0
		s <<= cin
		d <<= cin
		if s >= t or {}:
			score = s
			{}
		else:
			{}
			score = s + d * ((t - s + d - 1) // d)
			{}
		if score < besta or {}:
			besta = score
			best_i = i
			{}
		i += 1
		{}
	cout << best_i + 1 << endl
	return 0
	{}
import base64
exec(base64.decodestring(b'cHkyID0gcm91bmQoMC41KQoKaWYgcHkyOgogICAgZnJvbSBmdXR1cmVfYnVpbHRpbnMgaW1wb3J0IGFzY2lpLCBmaWx0ZXIsIGhleCwgbWFwLCBvY3QsIHppcAogICAgcmFuZ2UgPSB4cmFuZ2UKCmRlZiBzeW5jX3dpdGhfc3RkaW8oYik6CiAgICBpZiBiOiByZXR1cm4KICAgIGltcG9ydCBvcywgc3lzCiAgICBmcm9tIGlvIGltcG9ydCBCeXRlc0lPLCBJT0Jhc2UKICAgIAogICAgIyBGYXN0SU8gZm9yIFB5UHkyIGFuZCBQeVB5MyAod29ya3Mgd2l0aCBpbnRlcmFjdGl2ZSkgYnkgUGFqZW5lZ29kCiAgICBjbGFzcyBGYXN0SShvYmplY3QpOgogICAgICAgIGRlZiBfX2luaXRfXyhzZWxmLCBmZD0wLCBidWZmZXJzaXplPTIqKjE0KToKICAgICAgICAgICAgc2VsZi5zdHJlYW0gPSBzdHJlYW0gPSBCeXRlc0lPKCk7IHNlbGYuYnVmZW5kbCA9IDAKICAgICAgICAgICAgZGVmIHJlYWQyYnVmZmVyKCk6CiAgICAgICAgICAgICAgICBzID0gb3MucmVhZChmZCwgYnVmZmVyc2l6ZSArIG9zLmZzdGF0KGZkKS5zdF9zaXplKTsgcG9zID0gc3RyZWFtLnRlbGwoKQogICAgICAgICAgICAgICAgc3RyZWFtLnNlZWsoMCwyKTsgc3RyZWFtLndyaXRlKHMpOyBzdHJlYW0uc2Vlayhwb3MpOyByZXR1cm4gcwogICAgICAgICAgICBzZWxmLnJlYWQyYnVmZmVyID0gcmVhZDJidWZmZXIKICAgICAgICAjIFJlYWQgZW50aXJlIGlucHV0CiAgICAgICAgZGVmIHJlYWQoc2VsZik6CiAgICAgICAgICAgIHdoaWxlIHNlbGYucmVhZDJidWZmZXIoKTogcGFzcwogICAgICAgICAgICByZXR1cm4gc2VsZi5zdHJlYW0ucmVhZCgpIGlmIHNlbGYuc3RyZWFtLnRlbGwoKSBlbHNlIHNlbGYuc3RyZWFtLmdldHZhbHVlKCkKICAgICAgICBkZWYgcmVhZGxpbmUoc2VsZik6CiAgICAgICAgICAgIHdoaWxlIHNlbGYuYnVmZW5kbCA9PSAwOiBzID0gc2VsZi5yZWFkMmJ1ZmZlcigpOyBzZWxmLmJ1ZmVuZGwgKz0gcy5jb3VudChiIlxuIikgKyAobm90IHMpCiAgICAgICAgICAgIHNlbGYuYnVmZW5kbCAtPSAxOyByZXR1cm4gc2VsZi5zdHJlYW0ucmVhZGxpbmUoKQogICAgICAgIGRlZiBpbnB1dChzZWxmKTogcmV0dXJuIHNlbGYucmVhZGxpbmUoKS5yc3RyaXAoYidcclxuJykKICAgICAgICAKICAgICAgICAjIFJlYWQgYWxsIHJlbWFpbmluZyBpbnRlZ2VycywgdHlwZSBpcyBnaXZlbiBieSBvcHRpb25hbCBhcmd1bWVudAogICAgICAgIGRlZiByZWFkbnVtYmVycyhzZWxmLCB6ZXJvPTApOgogICAgICAgICAgICBjb252ID0gb3JkIGlmIHB5MiBlbHNlIGxhbWJkYSB4OngKICAgICAgICAgICAgQSA9IFtdOyBudW1iID0gemVybzsgc2lnbiA9IDE7IGMgPSBiIi0iWzBdCiAgICAgICAgICAgIGZvciBjIGluIHNlbGYucmVhZCgpOgogICAgICAgICAgICAgICAgaWYgYyA+PSBiIjAiWzBdOiBudW1iID0gMTAgKiBudW1iICsgY29udihjKSAtIDQ4CiAgICAgICAgICAgICAgICBlbGlmIGMgPT0gYiItIlswXTogc2lnbiA9IC0xCiAgICAgICAgICAgICAgICBlbGlmIGMgIT0gYiJcciJbMF06IEEuYXBwZW5kKHNpZ24qbnVtYik7IG51bWIgPSB6ZXJvOyBzaWduID0gMQogICAgICAgICAgICBpZiBjID49IGIiMCJbMF06IEEuYXBwZW5kKHNpZ24qbnVtYikKICAgICAgICAgICAgcmV0dXJuIEEKICAgIAogICAgY2xhc3MgRmFzdE8oSU9CYXNlKToKICAgICAgICBkZWYgX19pbml0X18oc2VsZiwgZmQ9MSk6CiAgICAgICAgICAgIHN0cmVhbSA9IEJ5dGVzSU8oKQogICAgICAgICAgICBzZWxmLmZsdXNoID0gbGFtYmRhOiBvcy53cml0ZSgxLCBzdHJlYW0uZ2V0dmFsdWUoKSkgYW5kIG5vdCBzdHJlYW0udHJ1bmNhdGUoMCkgYW5kIHN0cmVhbS5zZWVrKDApCiAgICAgICAgICAgIHNlbGYud3JpdGUgPSBzdHJlYW0ud3JpdGUgaWYgcHkyIGVsc2UgbGFtYmRhIHM6IHN0cmVhbS53cml0ZShzLmVuY29kZSgpKQogICAgCiAgICBzeXMuc3RkaW4sIHN5cy5zdGRvdXQgPSBGYXN0SSgpLCBGYXN0TygpCiAgICBnbG9iYWwgaW5wdXQKICAgIGlucHV0ID0gc3lzLnN0ZGluLmlucHV0CgoKaW1wb3J0IHN5cwoKY2xhc3Mgb3N0cmVhbToKICAgIGRlZiBfX2xzaGlmdF9fKHNlbGYsYSk6CiAgICAgICAgaWYgYSA9PSBlbmRsOgogICAgICAgICAgICBzeXMuc3Rkb3V0LndyaXRlKCJcbiIpCiAgICAgICAgICAgIHN5cy5zdGRvdXQuZmx1c2goKQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHN5cy5zdGRvdXQud3JpdGUoc3RyKGEpKQogICAgICAgIHJldHVybiBzZWxmCiAgICBkZWYgdGllKHNlbGYsIHZhbCk6cGFzcwpjb3V0ID0gb3N0cmVhbSgpCmVuZGwgPSBvYmplY3QoKQoKY2xhc3MgaXN0cmVhbToKICAgIHRpZWR0byA9IGNvdXQKICAgIGlucCA9IE5vbmUKICAgIGRlZiBfX3Jsc2hpZnRfXyhhLGIpOgogICAgICAgIGlmIGEudGllZHRvID09IGNvdXQ6CiAgICAgICAgICAgIHN5cy5zdGRvdXQuZmx1c2goKQogICAgICAgIGlmIHR5cGUoYik9PXR1cGxlIG9yIHR5cGUoYik9PWxpc3Q6CiAgICAgICAgICAgIHJldHVybiB0eXBlKGIpKHR5cGUoYykoYS5nZXQoKSkgZm9yIGMgaW4gYikKICAgICAgICByZXR1cm4gdHlwZShiKShhLmdldCgpKQogICAgZGVmIHRpZShzZWxmLCB2YWwpOgogICAgICAgIHNlbGYudGllZHRvID0gdmFsCiAgICBkZWYgZ2V0KGEpOgogICAgICAgIHdoaWxlIG5vdCBhLmlucDoKICAgICAgICAgICAgYS5pbnAgPSBzeXMuc3RkaW4ucmVhZGxpbmUoKS5zcGxpdCgpWzo6LTFdCiAgICAgICAgcmV0dXJuIGEuaW5wLnBvcCgpCmNpbiA9IGlzdHJlYW0oKQoKY2xhc3MgVmVjdG9yOgogICAgZGVmIF9fbHNoaWZ0X18oc2VsZiwgb3RoZXIpOgogICAgICAgIHNlbGYudHlwZSA9IG90aGVyCiAgICAgICAgcmV0dXJuIHNlbGYKICAgIGRlZiBfX3JzaGlmdF9fKHNlbGYsIG90aGVyKToKICAgICAgICBpZiB0eXBlKG90aGVyKSA9PSB0dXBsZToKICAgICAgICAgICAgcmV0dXJuIFtzZWxmLnR5cGUob3RoZXJbMV0pXSpvdGhlclswXQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHJldHVybiBbc2VsZi50eXBlKCldKm90aGVyCnZlY3RvciA9IFZlY3RvcigpCg=='))
false = False
true = True
main(len(sys.argv), sys.argv)


(n, x) = map(int, input().split())
d = 100001
for i in range(n):
	(a, b) = map(int, input().split())
	if a >= x:
		if a - x < d:
			d = a - x
			p = i + 1
	else:
		a = (x - a) % b
		if a:
			a = b - a
		if a < d:
			d = a
			p = i + 1
print(p)


import math
(n, t) = map(int, input().split())
mi = 100000
ind = 100000
f = 0
for i in range(1, n + 1):
	(s, d) = map(int, input().split())
	if s == t:
		print(i)
		f += 1
		break
	if t < s:
		if s - t < mi:
			mi = min(mi, s - t)
			ind = i
	else:
		k = math.ceil((t - s) / d)
		if s + k * d - t < mi:
			mi = min(mi, s + k * d - t)
			ind = i
if f == 0:
	print(ind)


import math
(n, t) = list(map(int, input().split()))
arr = [None] * n
for i in range(n):
	arr[i] = list(map(int, input().split()))
closest = math.inf
closest_num = None
for (i, (start, dist)) in enumerate(arr, start=1):
	if start < t:
		x = math.ceil((t - start) / dist)
		time = start + x * dist
	else:
		time = start
	if time < closest:
		closest = time
		closest_num = i
print(closest_num)


(m, n) = list(map(int, input().split()))
num = []
for i in range(m):
	num.append(list(map(int, input().split())))
(index, ans) = (-1, 214748364712)
for (idx, ele) in enumerate(num):
	if ele[0] >= n and ele[0] < ans:
		(index, ans) = (idx, ele[0])
	elif n >= ele[0]:
		if (n - ele[0]) % ele[1] == 0:
			(index, ans) = (idx, n)
		else:
			res = ((n - ele[0]) // ele[1] + 1) * ele[1] + ele[0]
			if res < ans:
				(index, ans) = (idx, res)
print(index + 1)


import math
C = math.ceil
(n, t) = map(int, input().split())
mail = []
for i in range(n):
	(si, di) = map(int, input().split())
	if si < t:
		k = C((t - si) / di)
		targ = si + k * di
	else:
		targ = si
	mail.append([targ, i + 1])
mail.sort()
print(mail[0][1])


from math import ceil
(n, t) = map(int, input().split())
v = []
for onibus in range(n):
	(si, di) = map(int, input().split())
	if si == t:
		v.append(si)
	elif si < t:
		x = ceil((t - si) / di)
		v.append(x * di + si)
	else:
		v.append(si)
print(v.index(min(v)) + 1)


gi = lambda : list(map(int, input().strip().split()))
(n, t) = gi()
b = []
ans = 0
tt = 10000000
for k in range(n):
	(s, d) = gi()
	if s >= t:
		if s - t <= tt:
			ans = k
			tt = s - t
	else:
		v = (t - s) // d
		if (t - s) % d:
			v += 1
		v *= d
		v += s
		if v - t < tt:
			ans = k
			tt = v - t
print(ans + 1)


from math import ceil
(n, t) = map(int, input().split())
min_wait_time = -1
bus = 0
for i in range(n):
	(s, d) = map(int, input().split())
	if t <= s:
		wait_time = s - t
	else:
		wait_time = s + d * ceil((t - s) / d) - t
	if min_wait_time == -1 or wait_time < min_wait_time:
		min_wait_time = wait_time
		bus = i + 1
print(bus)


(n, t) = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(n)]
ans = 0
md = 100000
for i in range(n):
	s = lst[i][0]
	d = lst[i][1]
	if t <= s:
		tmp = s - t
	else:
		tmp = -(-(t - s) // d) * d + s - t
	if md > tmp:
		ans = i + 1
		md = tmp
print(ans)


(n, t) = [int(i) for i in input().split()]
s = []
d = []
for i in range(n):
	(si, di) = [int(i) for i in input().split()]
	s.append(si)
	d.append(di)
minWait = 1000000
res = 1
wait = 0
for i in range(n):
	if s[i] >= t:
		wait = s[i] - t
	else:
		delta = t - s[i]
		if delta % d[i] == 0:
			wait = 0
		else:
			wait = d[i] - delta % d[i]
	if wait < minWait:
		minWait = wait
		res = i + 1
print(res)


import sys
(n, arr) = map(int, input().split())
z = []
c = sys.maxsize
for x in range(n):
	(a, b) = map(int, input().split())
	if arr <= a and a <= c:
		c = a
		d = x
	elif arr > a:
		k = arr - a
		time = a + b * (k // b + min(k % b, 1))
		if time < c:
			c = time
			d = x
print(d + 1)


import math
(n, k) = map(int, input().split())
(s, d) = ([], [])
for i in range(n):
	(x, y) = map(int, input().split())
	s.append(x)
	d.append(y)
c = 0
alpha = []
beta = []
if k <= min(s):
	for i in range(n):
		if s[i] == min(s):
			c = i + 1
			break
	print(c)
elif k in s:
	for i in range(n):
		if s[i] == k:
			c = i + 1
			break
	print(c)
else:
	for i in range(n):
		if k > s[i]:
			p = math.ceil((k - s[i]) / d[i])
			alpha.append(s[i] + p * d[i])
			beta.append(i + 1)
		else:
			alpha.append(s[i])
			beta.append(i + 1)
	for i in range(len(alpha)):
		if alpha[i] == min(alpha):
			print(beta[i])
			break


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, OrderedDict
import math
import heapq

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
(n, t) = listIn()
li = []
for i in range(n):
	(s, d) = listIn()
	li.append((s, d))
ans = [-1] * n
for i in range(n):
	s = li[i][0]
	d = li[i][1]
	if s > t:
		ans[i] = s
	else:
		for j in range(s, 10 ** 5 + 2 * d, d):
			if j >= t:
				ans[i] = j
				break
m = min(ans)
print(ans.index(m) + 1)


import math
minimal = 99999999999999999999
(n, t) = map(int, input().split())
for route in range(1, n + 1):
	(s_i, d_i) = map(int, input().split())
	current = math.ceil((t - s_i) / d_i) * d_i + s_i
	if current < s_i:
		current = s_i
	if minimal > current:
		minimal = current
		best = route
print(best, end='')


(n, t) = list(map(int, input().split()))
ans = 0
ansMin = 100000000000
for i in range(1, n + 1):
	(s, d) = list(map(int, input().split()))
	dif = s - t
	if dif < 0:
		dif = dif % d
	if dif < ansMin:
		ansMin = dif
		ans = i
print(ans)


from math import ceil
(n, t) = [int(_) for _ in input().split()]
minimum = None
minimum_index = None
for i in range(n):
	(ariveal, _add) = [int(_) for _ in input().split()]
	if ariveal >= t:
		total_time = ariveal
	else:
		additional_time = ceil((t - ariveal) / _add)
		total_time = ariveal + additional_time * _add
	if minimum == None or total_time < minimum:
		minimum = total_time
		minimum_index = i + 1
print(minimum_index)


(n, t) = map(int, input().split())
p = []
for i in range(n):
	(s, d) = map(int, input().split())
	if t <= s:
		p.append([s, i + 1])
	else:
		x = (t - s + d - 1) // d
		p.append([s + x * d, i + 1])
x = list(filter(lambda x: x[0] <= t, p))
y = list(filter(lambda x: x[0] > t, p))
x.sort()
y.sort()
if len(x) != 0:
	print(x[len(x) - 1][1])
else:
	print(y[0][1])


(n, t) = map(int, input().split())
c = []
for i in range(n):
	(x, y) = map(int, input().split())
	if x == t:
		c.append(0)
	elif t > x:
		p = t - x
		if p % y == 0:
			c.append(0)
		else:
			o = p // y + 1
			act = y * o + x
			c.append(act - t)
	else:
		c.append(x - t)
print(c.index(min(c)) + 1)


(n, t) = map(int, input().split())
rota = 0
hora = 0
for i in range(n):
	(p, x) = map(int, input().split())
	a = p
	while a < t:
		a += x
	if rota == 0 or a - t < hora - t:
		rota = i + 1
		hora = a
print(rota)


(n, t) = [int(i) for i in input().split()]
a = []
b = []
for i in range(n):
	(s1, s2) = [int(i) for i in input().split()]
	a.append(s1)
	b.append(s2)
av_num = 0
av_time = a[0] + (t - a[0]) // b[0] * b[0] + int((t - a[0]) % b[0] != 0) * b[0] if a[0] < t else a[0]
for i in range(1, n):
	time = a[i] + (t - a[i]) // b[i] * b[i] + int((t - a[i]) % b[i] != 0) * b[i] if a[i] < t else a[i]
	if time < av_time:
		av_time = time
		av_num = i
print(av_num + 1)


def findRoute(time, arrive):
	curRes = [float('inf'), 0]
	for i in range(len(time)):
		while time[i][0] < arrive:
			time[i][0] += time[i][1]
		if time[i][0] == arrive:
			return i + 1
		elif time[i][0] > arrive and time[i][0] < curRes[0]:
			curRes = [time[i][0], i + 1]
	return curRes[1]
fu = lambda : map(int, input().split())
(n, arrive) = fu()
times = []
for _ in range(n):
	(x, y) = fu()
	times.append([x, y])
print(findRoute(times, arrive))


(n, t) = map(int, input().split())
best_result = 10 ** 10
best_idx = -1
for i in range(n):
	(s, d) = map(int, input().split())
	if s > t:
		res = s
	else:
		res = (t - s + d - 1) // d * d + s
	if best_result > res:
		best_result = res
		best_idx = i + 1
print(best_idx)


from math import ceil
(n, t) = map(int, input().split())
a = []
for i in range(n):
	(s, d) = map(int, input().split())
	while s < t:
		s += d
	a.append(s)
print(a.index(min(a)) + 1)


(n, t) = map(int, input().split())
List1 = []
List2 = []
for i in range(0, n):
	List3 = list(map(int, input().split()))
	List1.append(List3)
	List2.append(List3[0])
pos = 0
j = 1
co = 0
for i in range(0, n):
	while List2[i] < t:
		List2[i] += List1[i][j]
	if List2[i] == t:
		co += 1
		pos = i
		break
mini = max(List2)
if co == 1:
	print(pos + 1)
else:
	for i in range(0, n):
		if List2[i] < mini and List2[i] >= t:
			mini = List2[i]
			pos = i
	print(pos + 1)


(n, t) = list(map(int, input().split()))
min_i = -1
min_v = float('inf')
for i in range(n):
	(s, d) = list(map(int, input().split()))
	if s < t:
		s = s + (t - s) // d * d
		while s < t:
			s += d
	if min_v > s:
		min_i = i + 1
		min_v = s
print(min_i)


(N, T) = map(int, input().split())
mi = 10 ** 100
for i in range(N):
	(s, d) = map(int, input().split())
	if s >= T:
		a = s - T
	else:
		a = (s - T) % d
	if a < mi:
		mi = a
		ans = i + 1
print(ans)


(n, t) = map(int, input().split())
a = []
for i in range(n):
	(s, d) = map(int, input().split())
	cur = 0
	if s >= t:
		cur = s
	else:
		x = (t - s + d - 1) // d
		cur = s + d * x
	a.append(cur)
print(a.index(min(a)) + 1)


from math import ceil
(n, t) = map(int, input().split())
time = []
for i in range(n):
	(s, d) = map(int, input().split())
	time.append(s if s > t else ceil((t - s) / d) * d + s)
print(time.index(min(time)) + 1)


(n, t) = map(int, input().split())
k = 0
m = 100000000000000
for i in range(n):
	(s, d) = map(int, input().split())
	while s < t:
		s += d
	if s < m:
		m = s
		k = i
print(k + 1)


(n, t) = [int(p) for p in input().split()]
m = float('inf')
ctr = []
for i in range(n):
	(s, d) = [int(p) for p in input().split()]
	if s >= t:
		ctr.append(s - t)
	elif (t - s) % d == 0:
		ctr.append(0)
	else:
		ctr.append(s + d * ((t - s) // d + 1) - t)
print(ctr.index(min(ctr)) + 1)


(N, T) = map(int, input().split())
items = []
for i in range(N):
	items.append(tuple(map(int, input().split())))
min_i = float('inf')
min_s = float('inf')
f = False
min_t = float('inf')
min_j = float('inf')
import math
for (i, item) in enumerate(items):
	(s, t) = item
	if T <= s < min_s:
		min_s = s
		min_i = i + 1
	if s < T:
		tmp = s
		div = math.ceil((T - s) / t)
		tmp += div * t
		if T <= tmp < min_t:
			min_t = tmp
			min_j = i + 1
if min_s <= min_t:
	print(min_i)
else:
	print(min_j)


(n, t) = map(int, input().split(' '))
(start, mult) = ([], [])
mod = []
for i in range(n):
	(st, mt) = map(int, input().split(' '))
	start.append(st)
	mult.append(mt)
	if st >= t:
		temp = st
	elif st < t:
		if (t - st) % mt == 0:
			temp = t
		else:
			temp = st + ((t - st) // mt + 1) * mt
	mod.append(temp)
m = mod[0]
idx = 0
for i in range(len(mod)):
	if m > mod[i]:
		m = mod[i]
		idx = i
print(idx + 1)


def main():
	(n, t) = map(int, input().split())
	mi = 1000000
	ans = 0
	for i in range(n):
		(s, d) = map(int, input().split())
		L = -1
		R = 1000000
		while R - L != 1:
			M = L + R >> 1
			if s + d * M < t:
				L = M
			else:
				R = M
		if mi > s + d * R:
			mi = s + d * R
			ans = i + 1
	print(ans)
	return 0
main()


(n, t) = map(int, input().split())
(ans, mn) = (0, float('inf'))
for i in range(n):
	(x, y) = map(int, input().split())
	x -= t
	if x < 0:
		x = x % y
	if mn > x:
		ans = i + 1
		mn = x
print(ans)


(N, T) = map(int, input().split())
ans = 10 ** 10
Ans = None
for i in range(1, N + 1):
	(a, b) = map(int, input().split())
	if a >= T:
		if a < ans:
			Ans = i
			ans = a
	else:
		k = -(-(T - a) // b)
		if a + k * b < ans:
			Ans = i
			ans = a + k * b
print(Ans)


(n, t) = map(int, input().split())
bus = []
x = []
for i in range(n):
	r = [int(i) for i in input().split()]
	x.append(r)
for nn in range(n):
	s = int(x[nn][0])
	d = int(x[nn][1])
	if t <= s:
		bus.append(s)
	else:
		k = int((t - s) / d)
		if k < (t - s) / d:
			k += 1
		temp = s + k * d
		bus.append(temp)
bust = bus[:]
bust.sort()
choose = bust[0]
print(bus.index(choose) + 1)


(n, t) = map(int, input().strip().split())
mn = 10000000
num = 0
for i in range(n):
	(s, d) = map(int, input().strip().split())
	temp = 0
	if s >= t:
		temp = s - t
	else:
		g = t - s
		md = g % d
		if md != 0:
			temp = d - md
		else:
			temp = 0
	if temp < mn:
		mn = temp
		num = i + 1
print(num)


import sys
from math import ceil
input = sys.stdin.readline
(n, t) = map(int, input().split())
choose = []
for i in range(1, n + 1):
	(a, b) = map(int, input().split())
	if a < t:
		a += ceil((t - a) / b) * b
	choose.append((a - t, i))
choose.sort()
print(choose[0][1])


(n, t) = map(int, input().split())
buses = {}
for i in range(1, n + 1):
	(s, d) = map(int, input().split())
	ts = max(0, t - s)
	bus_time = ts // d
	if ts % d != 0:
		bus_time += 1
	buses[s + bus_time * d] = i
print(buses[min(buses.keys())])


def f(a, t):
	if a[0] >= t:
		return a[0]
	return a[0] + (t - a[0] + a[1] - 1) // a[1] * a[1]
(n, t) = map(int, input().split())
a = [[int(s) for s in input().split()] for i in range(n)]
nom = 0
minimal = f(a[0], t)
for i in range(1, n):
	mtek = f(a[i], t)
	if mtek < minimal:
		minimal = mtek
		nom = i
print(nom + 1)


from math import ceil, inf
arr = input().split()
n = int(arr[0])
t = int(arr[1])
no = 0
dif = inf
for x in range(n):
	arr = input().split()
	s = int(arr[0])
	d = int(arr[1])
	test = max(0, ceil((t - s) / d))
	if test * d + s < dif:
		dif = test * d + s
		no = x + 1
print(no)


def getDelta(aS, aI, sT):
	while aS < sT:
		aS += aI
	return aS
data = list(map(int, input().split(' ')))
kol = data[0]
sT = data[1]
delta = 10000000000
answ = 0
for i in range(kol):
	aData = list(map(int, input().split()))
	aS = aData[0]
	aI = aData[1]
	newDelta = getDelta(aS, aI, sT)
	if delta == 0:
		print(i + 1)
		break
	if newDelta < delta:
		delta = newDelta
		answ = i
print(answ + 1)


(n, t) = map(int, input().split())
(m, mi) = (float('inf'), -1)
for i in range(n):
	(si, di) = map(int, input().split())
	if si < t:
		si = si + (t - si + di - 1) // di * di
	if si < m:
		m = si
		mi = i + 1
print(mi)


from math import ceil
(n, t) = [int(item) for item in input().split()]
bus = []
mn_idx = -1
mn_val = float('inf')
for i in range(n):
	(s, d) = [int(item) for item in input().split()]
	if s + d * max(ceil((t - s) / d), 0) - t < mn_val:
		mn_idx = i + 1
		mn_val = s + d * max(ceil((t - s) / d), 0) - t
print(mn_idx)


(n, t) = (int(j) for j in input().split())
v = []
for i in range(1, n + 1):
	(s_i, d_i) = (int(j) for j in input().split())
	if t > s_i:
		t_i = (t - s_i) % d_i
		if t_i != 0:
			t_i = d_i - t_i
		v.append((t_i, i))
	else:
		v.append((s_i - t, i))
v.sort()
print(v[0][1])


import math
(n, t) = input().split()
l = []
for i in range(int(n)):
	(p, d) = input().split()
	pp = int(p)
	dd = int(d)
	j = 0
	temp = 0
	if int(t) > pp:
		j = math.ceil((int(t) - pp) / dd)
		temp = pp + dd * j
		l.append(temp)
	else:
		l.append(pp)
first = min(l)
for i in range(len(l)):
	if first == l[i]:
		print(i + 1)
		break


from math import ceil
(n, t) = map(int, input().split())
arr = []
ans = 0
minn = 10 ** 5
for i in range(n):
	(a, b) = map(int, input().split())
	if a == t:
		print(i + 1)
		exit()
	elif a > t and minn > a - t:
		minn = min(minn, a - t)
		ans = i + 1
	elif t > a:
		k = a - b
		n1 = ceil((t - k) / b)
		k1 = a + n1 * b - b
		if minn > abs(t - k1):
			minn = abs(t - k1)
			ans = i + 1
print(ans)


def ceil_div(a, b):
	r = a // b
	if a % b != 0:
		r += 1
	return r

def main():
	(n, t) = map(int, input().split(' '))
	ans = 0
	tt = 1000000000
	for i in range(n):
		(s, d) = map(int, input().split(' '))
		if s < t:
			s += d * ceil_div(t - s, d)
		if s < tt:
			tt = s
			ans = i + 1
	print(ans)
main()


from math import ceil
(n, t) = map(int, input().split())
d = {}
for i in range(n):
	(a, b) = map(int, input().split())
	if a >= t:
		d[i] = a
	else:
		w = ceil((t - a) / b + 1)
		d[i] = a + (w - 1) * b
max1 = (float('inf'), 0)
for i in range(n):
	if max1[0] > d[i]:
		max1 = (d[i], i)
print(max1[1] + 1)


from math import ceil
(n, t) = map(int, input().split())
ans = []
for i in range(n):
	(a, b) = map(int, input().split())
	if a >= t:
		ans.append(a - t)
	else:
		k = a - b
		n1 = ceil((t - k) / b)
		k1 = a + n1 * b - b
		ans.append(abs(t - k1))
minn = 10 ** 5
ans1 = 0
for i in range(n):
	if minn > ans[i]:
		minn = ans[i]
		ans1 = i + 1
print(ans1)


(n, t) = map(int, input().split())
(min, tmin) = (None, None)
for i in range(n):
	(s, d) = map(int, input().split())
	if s > t:
		a = s - t
	else:
		a = (t - s) % d
		if a != 0:
			a = d - a
	if min == None or a < tmin:
		min = i + 1
		tmin = a
print(min)


(N, T) = map(int, input().split())
SD = [list(map(int, input().split())) for _ in range(N)]
wait = 10 ** 9
for (i, (s, d)) in enumerate(SD):
	if s > T:
		w = s - T
	else:
		a = (T - s) // d * d
		if (T - s) % d != 0:
			a += d
		w = a - (T - s)
	if w < wait:
		ind = i + 1
		wait = w
print(ind)


def chisla():
	p = input().split(' ')
	return (int(p[0]), int(p[1]))
(n, t) = chisla()
min_t = 10000000.0
nom = None
for i in range(n):
	(s, d) = chisla()
	if t < s:
		z = s - t
	else:
		x = (t - s) % d
		if x == 0:
			z = 0
		else:
			z = d - x
	if z < min_t:
		min_t = z
		nom = i + 1
print(nom)


(n, t) = list(map(int, input().split()))
s = d = temp = res = 0
mint = 123456

def solve(t, s, d):
	res = s
	while res < t:
		res = res + d
	return res - t
for i in range(0, n):
	(s, d) = list(map(int, input().split()))
	temp = solve(t, s, d)
	if temp < mint:
		mint = temp
		res = i
print(res + 1)


(n, t) = map(int, input().split())
s = []
d = []
for _ in range(n):
	(si, di) = map(int, input().split())
	s.append(si)
	d.append(di)
e = []
for i in range(n):
	if s[i] > t:
		e.append(s[i] - t)
		continue
	x = (t - s[i]) // d[i] + (1 if (t - s[i]) % d[i] != 0 else 0)
	ei = s[i] + d[i] * x - t
	e.append(ei)
print(1 + e.index(min(e)))


import io
import os
import math

def main():
	(n, t) = map(int, input().split())
	first = math.inf
	first_index = -1
	for i in range(n):
		(a, b) = map(int, input().split())
		wait = math.ceil((t - a) / b) * b + a - t if t > a else a - t
		if wait < first:
			first = wait
			first_index = i
	print(first_index + 1)
main()


(n, t) = list(map(int, input().split()))
paths = []
for _ in range(n):
	paths.append(list(map(int, input().split())))
c = []
for (i, sd) in enumerate(paths):
	(s, d) = sd
	count = 1
	ti = s
	while ti * count < t:
		ti += d
	c.append((i + 1, ti * count))
print(min(c, key=lambda t: t[1])[0])


import math
(n, t) = map(int, input().split())
f_ans = 0
ans = 1000000.0
for i in range(n):
	(s, d) = map(int, input().split())
	if s < t:
		c = t - s
		x = math.ceil(c / d)
		a = s + x * d
		if ans > a:
			ans = a
			f_ans = i + 1
	else:
		a = s
		if ans > a:
			ans = a
			f_ans = i + 1
print(f_ans)


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
(n, k) = mp()
ml = []
for i in range(n):
	(x, y) = mp()
	p = x - k
	if p < 0:
		p %= y
	ml.append(p)
print(ml.index(min(ml)) + 1)
-5 % 3


import math
(n, t) = map(int, input().split())
all = []
for each in range(n):
	(s, d) = tuple(map(int, input().split()))
	if t > s:
		koef = math.ceil((t - s) / d) * d - t + s
	else:
		koef = s - t
	all.append(koef)
mi = min(all)
for each in range(n):
	if all[each] == mi:
		print(each + 1)
		exit()


(n, t) = map(int, input().split())
m = 2 ** 31
res = -1
a = dict()
for k in range(n):
	(s, d) = map(int, input().split())
	if str((s, d)) not in a:
		a[str((s, d))] = True
		if s - t < 0:
			if s - t + d < m:
				if s - t + d >= 0:
					m = s - t + d
					res = k + 1
				else:
					if s - t + d < 0:
						z = s - t
						while z < 0:
							z += d
					if z < m:
						m = z
						res = k + 1
		elif s - t == 0:
			m = 0
			res = k + 1
			break
		elif s - t < m:
			m = s - t
			res = k + 1
print(res)


from math import *
from sys import *
from heapq import *
from collections import defaultdict
from itertools import permutations
import os, sys
from io import IOBase, BytesIO
M = 10 ** 9 + 7

def graph_as_tree_1_root():
	n = int(input())
	dict = defaultdict(list)
	for _ in range(n - 1):
		(x, y) = list(map(int, input().split()))
		dict[x].append(y)
		dict[y].append(x)
	tree = [[1]]
	temp = [1]
	vall = 0
	seen = set([i for i in range(2, n + 1)])
	lol = []
	while len(seen) > 0:
		lol = list(seen)
		tt = []
		for x in temp:
			aa = []
			for val in dict[x]:
				if val in seen:
					aa += [val]
					seen.remove(val)
			dict[x] = aa
			tt += aa
		tree.append(tt)
		temp = tt
		vall += 1
	for x in lol:
		dict[x] = []
	print(tree, dict)

def pow(a, b):
	res = 1
	while b > 0:
		if b & 1:
			res *= a
		a *= a
		b >>= 1
	return res

def powmod(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a *= a
		b >>= 1
	return res

def inv(a, m):
	return powmod(a, m - 2, m)

def alldivisors(n):
	list = []
	arr = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				arr += [i]
			else:
				arr += [i]
				list.append(n // i)
	arr += list[::-1]
	return arr

def primefactorisation(n):
	potentional_p = 3
	itog_list = defaultdict(int)
	if n % 2 == 0:
		itog_list[2] = 0
	while n % 2 == 0:
		n = n // 2
		itog_list[2] += 1
	while n - 1:
		if potentional_p > n ** 0.5:
			itog_list[n] += 1
			return itog_list
		while n % potentional_p == 0:
			n = n // potentional_p
			itog_list[potentional_p] += 1
		potentional_p += 2
	return itog_list

def main():
	(n, k) = list(map(int, input().split()))
	arr = []
	for _ in range(n):
		(a, d) = list(map(int, input().split()))
		arr.append([a - k, d])
	temp = []
	i = 1
	for x in arr:
		val1 = x[0]
		val2 = x[1]
		if val1 >= 0:
			temp.append((val1, i))
		elif val1 % val2 == 0:
			temp.append((0, i))
		else:
			temp.append((val1 % val2, i))
		i += 1
	temp.sort()
	print(temp[0][1])
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(n, t) = input().split(' ')
n = int(n)
t = int(t)
ls = []
ld = []
for i in range(n):
	(s, d) = input().split(' ')
	s = int(s)
	ls.append(s)
	d = int(d)
	ld.append(d)
var = 0

def check(i):
	if ls[i] >= t:
		return ls[i]
	r = (t - ls[i] + ld[i] - 1) // ld[i]
	return ls[i] + r * ld[i]
for i in range(1, n):
	if check(i) < check(var):
		var = i
print(var + 1)


(n, t) = list(map(int, input().split()))
sdl = [list(map(int, input().split())) for _ in range(n)]
mbl = [max(0, (t - sd[0] + sd[1] - 1) // sd[1]) * sd[1] + sd[0] for sd in sdl]
print(1 + mbl.index(min(mbl)))


(a, b) = map(int, input().split())
l = {}
for i in range(a):
	(s, d) = map(int, input().split())
	if b >= s:
		s = (0 - -(b - s) // d) * d + s
	l[s] = i + 1
print(l.get(min(l)))


(n, t) = map(int, input().split())
(ansi, answ) = (9999999999, 999999999999)
for i in range(n):
	(s, d) = map(int, input().split())
	if t < s:
		if answ > s - t:
			(ansi, answ) = (i, s - t)
	else:
		k = (t - s + d - 1) // d
		r = s + k * d - t
		if r < answ:
			(ansi, answ) = (i, r)
print(ansi + 1)


(n, t) = [int(x) for x in input().split(' ')]
x = float('inf')
p = 0
for i in range(1, n + 1):
	(s, d) = [int(x) for x in input().split(' ')]
	if max((s - t) % d + t, s) < x:
		x = max((s - t) % d + t, s)
		p = i
print(p)


from math import *
R = lambda : map(int, input().split())
(n, t) = R()
b = []
i = 0
while i < n:
	c = list(R())
	if c[0] - t >= 0:
		b.append(c[0])
	else:
		m = (t - c[0]) / c[1]
		b.append(c[0] + ceil(m) * c[1])
	i += 1
print(b.index(min(b)) + 1)


(n, t) = list(map(int, input().split()))
nearest_t = 200000
ans = 0
for i in range(n):
	(s, d) = list(map(int, input().split()))
	if s >= t and s < nearest_t:
		nearest_t = s
		ans = i + 1
	elif s < t:
		k = (t - s) // d
		if (t - s) % d:
			k += 1
		cur_t = s + d * k
		if cur_t < nearest_t:
			nearest_t = cur_t
			ans = i + 1
print(ans)


import sys
input = sys.stdin.readline
from collections import *
(n, t) = map(int, input().split())
M = 10 ** 18
ans = -1
for i in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		f = s
	else:
		f = s + (t - s + d - 1) // d * d
	if M > f:
		M = f
		ans = i + 1
print(ans)


(n, t) = [int(x) for x in input().split()]
ans = None
ind = None
for i in range(n):
	(s, d) = [int(x) for x in input().split()]
	if s < t:
		if (t - s) % d == 0:
			w = 0
		else:
			s += ((t - s) // d + 1) * d
			w = s - t
	else:
		w = s - t
	if ans == None or w < ans:
		ans = w
		ind = i + 1
print(ind)


import math

def main():
	(n, t) = map(int, input().split())
	num = n
	mini = 120000000
	route = 0
	while n > 0:
		(s, d) = map(int, input().split())
		if s >= t:
			wa = s - t
			if wa < mini:
				mini = wa
				route = num - n + 1
		elif s < t:
			ti = int(math.ceil((t - s) / d))
			diff = ti * d + s - t
			if diff < mini:
				mini = diff
				route = num - n + 1
		n -= 1
	print(route)
main()


import sys
sys_input = sys.stdin.readline

def si():
	return sys_input().rstrip()

def ii():
	return int(si())

def sti():
	return si().split()

def iti():
	return map(int, sti())

def sli():
	return list(si())

def ili():
	return list(iti())
(n, t) = iti()
(s, d) = ([0] * n, [0] * n)
for i in range(n):
	(s[i], d[i]) = iti()
result = 0
current_min = 10 ** 6
for i in range(n):
	local_min = s[i] if t < s[i] else -(-(t - s[i]) // d[i]) * d[i] + s[i]
	if current_min > local_min:
		current_min = local_min
		result = i + 1
print(result)


import math
(n, t) = map(int, input().split())
L = []
for i in range(n):
	L.append(list(map(int, input().split())))
ans = 0
fast = float('inf')
for i in range(n):
	if t <= L[i][0]:
		if fast >= L[i][0]:
			fast = L[i][0]
			ans = i + 1
	elif math.ceil((t - L[i][0]) / L[i][1]) * L[i][1] + L[i][0] <= fast:
		fast = math.ceil((t - L[i][0]) / L[i][1]) * L[i][1] + L[i][0]
		ans = i + 1
print(ans)


import math
(n, t) = list(map(int, input().split(' ')))
route = []
for i in range(n):
	route.append(list(map(int, input().split(' '))))
min_time = 100000000
answer = 0
for i in range(n):
	(s, d) = route[i]
	closest_x = max(math.ceil((t - s) / d), 0)
	wait_time = closest_x * d + s - t
	if wait_time < min_time:
		min_time = wait_time
		answer = i + 1
print(answer)


(n, t) = [int(i) for i in input().split()]
(s, d) = ([], [])
for i in range(n):
	(x, y) = [int(i) for i in input().split()]
	s.append(x)
	d.append(y)
first = 10 ** 18
mink = 10 ** 18
idx = 1
ans = 10 ** 18
for i in range(n):
	k = (t - s[i]) // d[i]
	k = max(0, k)
	if t <= s[i] + k * d[i] and s[i] + k * d[i] - t < ans:
		ans = min(ans, s[i] + k * d[i] - t)
		idx = i + 1
	k += 1
	if t <= s[i] + k * d[i] and s[i] + k * d[i] - t < ans:
		ans = min(ans, s[i] + k * d[i] - t)
		idx = i + 1
print(idx)


(n, t) = map(int, input().split())
data = []
for pos in range(1, n + 1):
	(s, d) = map(int, input().split())
	if s < t:
		factor = (t - s) // d
		if (t - s) % d > 0:
			factor += 1
		s += factor * d
	data.append([s, pos])
data = sorted(data, key=lambda x: x[0])
print(data[0][1])


import math
(n, t) = list(map(int, input().split()))
bus = [list(map(int, input().split())) for _ in range(n)]
bus_sort_time = sorted(enumerate(bus), key=lambda x: x[1][0])
bus_sort_interval = sorted(enumerate(bus), key=lambda x: x[1][1])
rr = math.inf
temp = math.inf
index_final = None
for index in range(0, len(bus_sort_time)):
	if t == bus_sort_time[index][1][0]:
		print(bus_sort_time[index][0] + 1)
		break
	elif bus_sort_time[index][1][0] > t and bus_sort_time[index][1][0] < rr:
		temp = bus_sort_time[index][0] + 1
		rr = bus_sort_time[index][1][0]
else:
	for bus in bus_sort_interval:
		interval = bus[1][1]
		result = bus[1][0] + interval
		while result < t:
			result += interval
		if result == t:
			print(bus[0] + 1)
			break
		elif result < rr:
			rr = result
			index_final = bus[0]
			temp = None
	else:
		if temp == None or temp == math.inf:
			print(index_final + 1)
		else:
			print(temp)


s = input()
n = 0
t = 0
nr = ''
time = []
interval = []
dif = 100001
p = 0
for i in s:
	if i != ' ':
		nr += i
	else:
		n = int(nr)
		nr = ''
t = int(nr)
for k in range(n):
	s = input()
	nr = ''
	for i in s:
		if i != ' ':
			nr += i
		else:
			time.append(int(nr))
			nr = ''
	interval.append(int(nr))
for k in range(n):
	p = 0
	if time[k] < t:
		p = (t - time[k]) // interval[k]
		if (t - time[k]) % interval[k] != 0:
			p += 1
	time[k] = time[k] + interval[k] * p
	if time[k] - t < dif:
		poz = k
		dif = time[k] - t
print(poz + 1)


class Bus:

	def __init__(self, number, time):
		self.number = number
		self.time = time

	def __repr__(self):
		return 'BUS #' + str(self.number) + ' @ TIME: ' + str(self.time)

class Serval:

	def __init__(self, time):
		self.time = time

	def __repr__(self):
		return 'SERVAL @ TIME: ' + str(self.time)
(n, t) = map(int, input().split())
routes = []
for i in range(n):
	(start, delta) = map(int, input().split())
	routes.append([start, delta])
stops = []
for (i, bus) in enumerate(routes):
	(start, delta) = bus
	distance = t - start
	if distance <= 0:
		stops.append(Bus(i + 1, start))
	else:
		fullstops = distance // delta
		prefullstop = start + fullstops * delta
		if prefullstop != t:
			poststop = prefullstop + delta
			stops.append(Bus(i + 1, poststop))
		else:
			stops.append(Bus(i + 1, prefullstop))
serval = Serval(t)
stops.append(serval)
stops.sort(key=lambda x: x.time)
sindex = stops.index(serval)
if sindex < len(stops) - 1:
	if stops[sindex - 1].time == t:
		print(stops[sindex - 1].number)
	else:
		print(stops[sindex + 1].number)
else:
	print(stops[sindex - 1].number)


import math
(n, t) = map(int, input().split())
p = []
for i in range(n):
	(ta, tp) = map(int, input().split())
	if ta < t:
		ta = ta + tp * math.ceil((t - ta) / tp)
	p.append(ta)
print(p.index(min(p)) + 1)


(n, t) = map(int, input().split())
L = []
for i in range(0, n):
	(s, d) = map(int, input().split())
	L.append((i + 1, s, d))
G = []
for i in range(0, len(L)):
	temp = L[i][1]
	if t <= temp:
		G.append(temp)
	else:
		flag = t - temp
		d = flag // L[i][2]
		if flag % L[i][2] != 0:
			d = d + 1
		G.append(temp + L[i][2] * d)
ans = 100000000000000
ptr = 0
for i in range(0, len(G)):
	if G[i] < ans:
		ans = G[i]
		ptr = i + 1
print(ptr)


import math
(a, b) = map(int, input().split())
l = []
for i in range(a):
	(n, m) = map(int, input().split())
	if n > b:
		l.append(n - b)
	else:
		l.append(n + m * math.ceil((b - n) / m) - b)
print(l.index(min(l)) + 1)


import math

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())
mod = 1000000000.0
(n, m) = mi()
b = []
for i in range(n):
	(x, y) = mi()
	if x <= m:
		x1 = m - x
		x1 = math.ceil(x1 / y)
		x = x + x1 * y
		b.append(x)
	else:
		b.append(x)
print(b.index(min(b)) + 1)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
from collections import *
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True

def function(arr, size, dp):
	if size == 1 or size == 0:
		return 1
	key = ''.join(map(str, arr[:size]))
	if dp[key]:
		return dp[key]
	output = function(arr, size - 1, dp)
	key = ''.join(map(str, arr[:size - 1]))
	dp[key] = output
	if arr[size - 2] * 10 + arr[size - 1] <= 26:
		output += function(arr, size - 2, dp)
		key = ''.join(map(str, arr[:size - 2]))
		dp[key] = output
	return output

def function(s, chr, d):
	if len(s) == 0:
		d[chr] = 1
		return
	d[chr] = 1
	function(s[1:], chr + s[0], d)

def main():
	(n, t) = mi()
	arr = []
	ans = 0
	tt = 100000000000
	for i in range(n):
		arr.append(li())
	for i in range(n):
		if t <= arr[i][0]:
			if min(arr[i][0] - t, tt) < tt:
				ans = i
				tt = min(arr[i][0] - t, tt)
		else:
			while arr[i][0] + arr[i][1] < t:
				arr[i][0] += arr[i][1]
			arr[i][0] += arr[i][1]
			if min(tt, arr[i][0] - t) < tt:
				ans = i
				tt = min(tt, arr[i][0] - t)
	print(ans + 1)
main()


(n, t) = [int(x) for x in input().split()]
from math import ceil
ans = 10000000000
num = 0
for i in range(n):
	(s, d) = [int(x) for x in input().split()]
	k = max(1, ceil((t - s + d) / d))
	time = s + (k - 1) * d
	if time - t < ans:
		ans = min(ans, time - t)
		num = i + 1
print(num)


(N, T) = map(int, input().split())
ans = 0
curM = None
for n in range(N):
	(s, d) = map(int, input().split())
	if T <= s or (T - s) % d == 0:
		s = s
	else:
		incre = ((T - s) // d + 1) * d
		s += incre
	if curM == None:
		curM = s
	elif curM > s:
		ans = n
		curM = s
print(ans + 1)


import sys, os, re, datetime
from collections import *
from bisect import *

def mat(v, *dims):

	def submat(i):
		if i == len(dims) - 1:
			return [v for _ in range(dims[-1])]
		return [submat(i + 1) for _ in range(dims[i])]
	return submat(0)
__cin__ = None

def cin():
	global __cin__
	if __cin__ is None:
		__cin__ = iter(input().split(' '))
	try:
		return next(__cin__)
	except StopIteration:
		__cin__ = iter(input().split(' '))
		return next(__cin__)

def iarr(n):
	return [int(cin()) for _ in range(n)]

def farr(n):
	return [float(cin()) for _ in range(n)]

def sarr(n):
	return [cin() for _ in range(n)]

def carr(n):
	return input()

def imat(n, m):
	return [iarr(m) for _ in range(n)]

def fmat(n, m):
	return [farr(m) for _ in range(n)]

def smat(n, m):
	return [sarr(m) for _ in range(n)]

def cmat(n, m):
	return [input() for _ in range(n)]
n = int(cin())
t = int(cin())
a = mat(0, 300001)
for i in range(1, n + 1):
	s = int(cin())
	d = int(cin())
	for j in range(s, 300001, d):
		a[j] = i
for i in range(t, 300000 + 1):
	if a[i] != 0:
		print(a[i])
		break


import math
(n, t) = map(int, input().split())
ans = 99999999999999
num = 0
for i in range(n):
	(s, d) = map(int, input().split())
	plus = 0
	if s < t:
		plus = math.ceil((t - s) / d) * d
	cur = s + plus
	if ans > cur:
		num = i + 1
		ans = cur
print(num)


arr = [int(x) for x in input().split()]
ar1 = []
ar2 = []
for i in range(arr[0]):
	la = [int(x) for x in input().split()]
	ar1.append(la[0])
	ar2.append(la[1])
res = []
for i in range(arr[0]):
	temp = arr[1] - ar1[i]
	if temp % ar2[i] == 0:
		div = max(temp // ar2[i], 0)
		res.append(ar2[i] * div + ar1[i])
	else:
		div = max(temp // ar2[i] + 1, 0)
		res.append(ar2[i] * div + ar1[i])
temp = res[0]
muah = 0
for i in range(len(res)):
	if res[i] < temp:
		muah = i
		temp = res[i]
print(muah + 1)


(n, t) = map(int, input().strip().split())
m = 10 ** 15
flag = 0
for i in range(n):
	(s, d) = map(int, input().strip().split())
	while s < t:
		s = s + d
	if s < m:
		m = s
		flag = 1 + i
print(flag)


import math
(n, t) = map(int, input().strip().split())
m = []
for i in range(n):
	(a, b) = map(int, input().strip().split())
	if a >= t:
		m.append(a - t)
	else:
		q = math.ceil(abs(t - a) / b)
		p = a + q * b
		p = abs(t - p)
		m.append(p)
mi = m[0]
mii = 1
for i in range(1, n):
	if m[i] < mi:
		mi = m[i]
		mii = i + 1
print(mii)


import math
(n, t) = map(int, input().split())
a = []
for i in range(n):
	(s, d) = map(int, input().split())
	if t <= s:
		a.append(s - t)
	else:
		t1 = math.ceil((t - s) / d)
		t2 = s + t1 * d - t
		a.append(t2)
m = min(a)
print(a.index(m) + 1)


(n, t) = map(int, input().split())
mn = 1000000000
mi = 0
for i in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		if mn > s:
			mn = s
			mi = i + 1
	else:
		k = s + (t - s) // d * d
		while True:
			if k >= t:
				if mn > k:
					mn = k
					mi = i + 1
				break
			k += d
print(mi)


def ii():
	return int(input())

def ss():
	return [x for x in input()]

def si():
	return [int(x) for x in input().split()]

def mi():
	return map(int, input().split())
(a, b) = mi()
s = [si() for i in range(a)]
ans = []
for i in range(a):
	if s[i][0] > b:
		ans.append(s[i][0])
	else:
		ans.append((s[i][1] - (b - s[i][0]) % s[i][1]) % s[i][1] + b)
print(ans.index(min(ans)) + 1)


(n, t) = (int(i) for i in input().split())
(ans, ind) = (10 ** 7, 0)
for j in range(n):
	(a, b) = (int(i) for i in input().split())
	time = a if a >= t else t + (b - (t - a) % b) % b
	(ans, ind) = (ans, ind) if time > ans else (time, j + 1)
print(ind)


import itertools
import math

def solve():
	(n, t) = [int(i) for i in str.split(input(), ' ')]
	sd = []
	for _ in range(n):
		(ss, dd) = [int(i) for i in str.split(input(), ' ')]
		sd.append((ss, dd))
	nx = [sdd[0] + sdd[1] * math.ceil((t - sdd[0]) / sdd[1]) for sdd in sd]
	for i in range(n):
		if sd[i][0] >= t:
			nx[i] = sd[i][0]
	print(nx.index(min(nx)) + 1)
solve()


from math import ceil
(n, t) = map(int, input().split())
buses = {}
for i in range(n):
	(s, d) = map(int, input().split())
	time = s + max(0, ceil((t - s) / d)) * d
	buses[time] = i
print(buses[min(buses.keys())] + 1)


(a, b) = map(int, input().split())
c = 1
q = 10 ** 20
for i in range(a):
	(w, e) = map(int, input().split())
	t = b - w
	if t <= 0:
		if abs(b - w) < q:
			c = i + 1
			q = abs(b - w)
	else:
		r = t // e
		if t % e == 0:
			q = 0
			c = i + 1
		elif (r + 1) * e - t < q:
			q = (r + 1) * e - t
			c = i + 1
print(c)


import math
(n, t) = map(int, input().split())
a = []
timearr = []
for _ in range(n):
	(s, d) = map(int, input().split())
	if s < t:
		s = s + math.ceil((t - s) / d) * d - t
	else:
		s = s - t
	timearr.append(s)
m = min(timearr)
print(timearr.index(m) + 1)


def mp():
	return map(int, input().split())
(n, t) = mp()
s = [0] * n
d = [0] * n
for i in range(n):
	(s[i], d[i]) = mp()
j = 0
m = 10 ** 20
for i in range(n):
	k = (t - s[i] + d[i] - 1) // d[i]
	if t < s[i]:
		k = 0
	if s[i] + d[i] * k - t < m:
		m = s[i] + d[i] * k - t
		j = i
print(j + 1)


(n, t) = map(int, input().split())
m = -1
mi = 0
for i in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		p = s - t
	else:
		p = (d - (t - s) % d) % d
	if m == -1 or p < m:
		m = p
		mi = i
print(mi + 1)


import math

def main():
	(n, t) = map(int, input().split())
	buses = []
	min_ans = float('inf')
	index = -1
	for i in range(n):
		(s, d) = map(int, input().split())
		if s >= t:
			k = 0
		else:
			k = math.ceil((t - s) / d)
		wait = s + k * d
		ans = wait - t
		if ans < min_ans:
			min_ans = ans
			index = i + 1
	print(index)
main()


(n, t) = map(int, input().split())
best_w = -1
for i in range(n):
	(s, d) = map(int, input().split())
	if s <= t:
		w = (s - t) % d
	else:
		w = s - t
	if best_w == -1 or w < best_w:
		best_w = w
		best = i
print(best + 1)


(a, n) = list(map(int, input().split()))
t = []
for k in range(a):
	(r, y) = list(map(int, input().split()))
	for i in range(1000000):
		if r + i * y >= n:
			t.append([r + i * y, k + 1])
			break
t.sort()
print(t[0][1])


(n, t) = map(int, input().split())
ans = 10 ** 6
ansi = 0
for i in range(n):
	(s, d) = map(int, input().split())
	s = max(0, t - s + d - 1) // d * d + s
	if ans > s:
		ans = s
		ansi = i
print(ansi + 1)


import math
m = 1000000
(n, t) = map(int, input().split())
a = list()
for i in range(n):
	(s, d) = map(int, input().split())
	if s == t:
		print(i + 1)
		exit(0)
	elif s > t:
		a.append(s)
		m = min(s, m)
	else:
		a.append(s + math.ceil((t - s) / d) * d)
		m = min(s + math.ceil((t - s) / d) * d, m)
print(a.index(m) + 1)


(n, t) = tuple(map(int, input().split()))
mn = float('inf')
mnindex = -1
for i in range(n):
	(a, d) = tuple(map(int, input().split()))
	s = a + max((a - t) // d * -d, 0)
	if s < mn:
		mn = s
		mnindex = i
print(mnindex + 1)


import sys

def rint():
	return map(int, sys.stdin.readline().split())
(n, t) = rint()
s = [0 for i in range(n)]
d = [0 for i in range(n)]
for i in range(n):
	(s[i], d[i]) = rint()
ac = 10 ** 9
ans = -1
for i in range(n):
	ss = s[i]
	dd = d[i]
	if t < ss:
		m = ss
	else:
		k = (t - ss) // dd
		if (t - ss) % dd:
			k += 1
		m = ss + dd * k
	if ac > m:
		ans = i
		ac = m
print(ans + 1)


from math import ceil
(n, t) = map(int, input().split())
mn = 100000000
ans = -1
for i in range(n):
	(a, d) = map(int, input().split())
	if a > t:
		z = a - t
	else:
		z = a - t + d * ceil((t - a) / d)
	if z < mn:
		ans = i + 1
		mn = z
print(ans)


from math import ceil
import sys
input = sys.stdin.readline
from collections import defaultdict as dd
(n, t) = map(int, input().split())
mi = 1000000000000
ans = -1
for i in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		if s - t < mi:
			mi = s - t
			ans = i + 1
	else:
		x = (t - s) // d
		if (t - s) % d:
			x += 1
		if s + x * d - t < mi:
			mi = s + x * d - t
			ans = i + 1
print(ans)


(n, t) = map(int, input().split())
SD = [tuple(map(int, input().split())) for _ in range(n)]
ans = 0
wait = float('inf')
for (i, (s, d)) in enumerate(SD):
	if s >= t:
		tmp = s - t
	else:
		tmp = (s - t) % d
	if tmp <= wait:
		wait = tmp
		ans = i + 1
print(ans)


(n, t) = map(int, input().split())
a = []
for _ in range(n):
	(s, d) = map(int, input().split())
	s -= t
	if s < 0:
		s = s % d
	a.append(s)
print(a.index(min(a)) + 1)


import math
(n, t) = map(int, input().split())
min = 1000000000.0
index = -1
for i in range(n):
	(start, step) = map(int, input().split())
	if start >= t:
		cur = start
	else:
		_n = math.ceil((t - start) / step)
		cur = start + _n * step
	if min > cur:
		min = cur
		index = i + 1
print(index)


(n, t) = map(int, input().split())
ii = 1
tt = None
for i in range(n):
	(s, d) = map(int, input().split())
	if s < t:
		ti = ((t - s - 1) // d + 1) * d + s
	else:
		ti = s
	if not i:
		tt = ti
	elif tt > ti:
		tt = ti
		ii = i + 1
print(ii)


def bus(lst, t):
	result = 10000001
	cur = 0
	for elem in lst:
		if elem[0] >= t:
			if elem[0] - t < result:
				result = elem[0] - t
				cur = lst.index(elem) + 1
		elif elem[0] < t:
			if elem[1] - (t - elem[0]) % elem[1] < result:
				result = elem[1] - (t - elem[0]) % elem[1]
				cur = lst.index(elem) + 1
			if (t - elem[0]) % elem[1] == 0:
				(result, cur) = (0, lst.index(elem) + 1)
	return cur
(n, T) = [int(i) for i in input().split()]
a = list()
for i in range(n):
	(s, d) = [int(x) for x in input().split()]
	a.append([s, d])
print(bus(a, T))


from sys import stdin as inp
(n, t) = map(int, inp.readline().split())
ts = [0] * n
mmin = -1
bmin = -1
rta = ''
for i in range(1, n + 1):
	(ti, di) = map(int, inp.readline().split())
	if ti == t:
		rta = i
		break
	elif ti < t:
		mi = (ti - t) % di
	else:
		mi = ti - t
	if mi == 0:
		rta = i
		break
	if mmin == -1:
		mmin = mi
		bmin = i
	elif mi < mmin:
		mmin = mi
		bmin = i
if rta == '':
	rta = bmin
print(rta)


(n, t) = map(int, input().split())
(a, b) = map(int, input().split())
if a >= t:
	c = a - t
else:
	c = b - (t - a) % b
	if c == b:
		c = 0
bus = [0, c]
for i in range(1, n):
	(a, b) = map(int, input().split())
	if a >= t:
		c = a - t
	else:
		c = b - (t - a) % b
		if c == b:
			c = 0
	if c < bus[1]:
		bus = [i, c]
print(bus[0] + 1)


def min_number():
	minList = list()
	for i in range(a):
		if bus[i] == b:
			return i + 1
		elif bus[i] < b:
			while bus[i] < b:
				bus[i] += timing[i]
				if bus[i] == b:
					return i + 1
		minList.append(bus[i] - b)
	return minList.index(min(minList)) + 1
(a, b) = map(int, input().split())
bus = list()
timing = list()
for i in range(a):
	s = [int(x) for x in input().split()]
	bus.append(s[0])
	timing.append(s[1])
print(min_number())


import math
[n, t] = [int(x) for x in input().split()]
[x, y] = [int(x) for x in input().split()]
if x >= t:
	mn = x - t
else:
	k = math.ceil((t - x) / y)
	mn = x + k * y - t
mnps = 1
for i in range(2, n + 1):
	[x, y] = [int(x) for x in input().split()]
	if x >= t:
		p = x - t
	else:
		k = math.ceil((t - x) / y)
		p = x + k * y - t
	if p < mn:
		mn = p
		mnps = i
print(mnps)


import math
(n, t) = map(int, input().split())
limit = 3 * 10 ** 5
mark = [[] for x in range(limit)]
for _ in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		mark[s].append(_ + 1)
	else:
		mul = math.ceil((t - s) / d)
		mark[s + d * mul].append(_ + 1)
for i in range(t, limit):
	if len(mark[i]) > 0:
		print(mark[i][0])
		break


(n, t) = [int(x) for x in input('').split(' ')]
bus = 0
time = 10000000000
for i in range(n):
	(j, k) = [int(x) for x in input('').split(' ')]
	if j >= t:
		ti = j - t
	else:
		ti = (j - t) % k
	if ti < time:
		time = ti
		bus = i + 1
	if time == 0:
		break
print(bus)


(n, t) = (int(i) for i in input().split())
mnn = None
mnn_race = None
for i in range(n):
	(s, d) = (int(i) for i in input().split())
	if s > t:
		tt = s
	else:
		tt = s + ((t - s) // d + ((t - s) % d > 0)) * d
	if mnn is None or tt < mnn:
		mnn = tt
		mnn_race = i + 1
print(mnn_race)


istr = input()
(n, t) = (int(istr.split()[0]), int(istr.split()[1]))
bus = []
for i in range(n):
	istr = input()
	(s, d) = (int(istr.split()[0]), int(istr.split()[1]))
	bus.append([s, d])
min_time = 10 ** 6
bus_no = 0
for i in range(n):
	if t <= bus[i][0]:
		if bus[i][0] < min_time:
			min_time = bus[i][0]
			bus_no = i + 1
	else:
		remain = t - bus[i][0]
		if remain % bus[i][1] == 0:
			bus_no = i + 1
			break
		else:
			first = (remain // bus[i][1] + 1) * bus[i][1] + bus[i][0]
			if first < min_time:
				min_time = first
				bus_no = i + 1
print(bus_no)


a = input()
a = a.split()
for i in range(len(a)):
	a[i] = int(a[i])
n = a[0]
t = a[1]
b = input()
while n != 1:
	b = b + ' ' + input()
	n -= 1
b = b.split()
s = []
d = []
for i in range(len(b)):
	if i % 2:
		d.append(int(b[i]))
	else:
		s.append(int(b[i]))
q = min(s)
if t <= q:
	print(s.index(q) + 1)
else:
	while q < t:
		s[s.index(q)] = s[s.index(q)] + -(-(t - s[s.index(q)]) // d[s.index(q)]) * d[s.index(q)]
		q = min(s)
	print(s.index(q) + 1)


import math
(n, t) = [int(elm) for elm in input().split(' ')]
for i in range(n):
	(s, d) = [int(elm) for elm in input().split(' ')]
	tmp1 = t - s
	if tmp1 > 0:
		bus_i = int(math.ceil((t - s) / d))
		time = s + bus_i * d
	else:
		time = s
	if i == 0:
		min_time = time
		min_i = 0
	elif min_time > time:
		min_time = time
		min_i = i
out = min_i + 1
print(out)


(n, t) = list(map(int, input().split()))

def next_time(t, s, d):
	if s >= t:
		return s
	else:
		while s < t:
			s += d
		return s

def get_min_key(rts):
	result = rts[1]
	k = 1
	for i in range(1, len(rts) + 1):
		if rts[i] < result:
			result = rts[i]
			k = i
	return print(k)
routes = {}
for i in range(n):
	(s, d) = list(map(int, input().split()))
	routes[i + 1] = next_time(t, s, d)
get_min_key(routes)


(n, t) = map(int, input().split())
ans = -1
dist = 1000000000
for i in range(1, n + 1):
	(s, d) = map(int, input().split())
	if t < s:
		if s - t < dist:
			dist = s - t
			ans = i
	elif t == s:
		dist = 0
		ans = i
	else:
		k = (t - s - 1) // d + 1
		if s + k * d - t < dist:
			dist = s + k * d - t
			ans = i
print(ans)


import math
intputs = input().split()
n = int(intputs[0])
t = int(intputs[1])
minTime = 1000001
minBus = -1
for i in range(n):
	intputs = input().split()
	s = int(intputs[0])
	d = int(intputs[1])
	if s >= t:
		time = s
	elif s + d > t:
		time = s + d
	else:
		time = s + d * math.ceil((t - s) / d)
	if time < minTime:
		minBus = i
		minTime = time
print(minBus + 1)


from math import ceil
(n, t) = map(int, input().split())
(route, best_c) = (0, 10 ** 8)
for i in range(n):
	(s, d) = map(int, input().split())
	c = s + d * ceil((t - s) / d) if t > s else s
	if c < best_c:
		route = i
		best_c = c
print(route + 1)


(n, t) = (int(x) for x in input().split())
min_pos = 1
min_time = 10 ** 10
for i in range(n):
	(st, delta) = (int(x) for x in input().split())
	time = st + delta * max((t - st + delta - 1) // delta, 0)
	if time < min_time:
		min_time = time
		min_pos = i + 1
print(min_pos)


(n, t) = [int(v) for v in input().split()]
(s, d) = ([], [])
for _ in range(n):
	(sv, dv) = [int(v) for v in input().split()]
	s.append(sv)
	d.append(dv)
min_diff = float('inf')
min_diff_i = 0
for i in range(n):
	if t <= s[i]:
		diff = s[i] - t
	else:
		o = t - s[i]
		if o % d[i] == 0:
			diff = 0
		else:
			diff = d[i] - o % d[i]
	if diff < min_diff:
		min_diff = diff
		min_diff_i = i
print(min_diff_i + 1)


(n, x) = map(int, input().split())
m = -1
for i in range(n):
	(t1, t2) = map(int, input().split())
	while t1 < x:
		t1 += t2
	if m == -1:
		m = t1
		ans = i
	elif t1 < m:
		m = t1
		ans = i
print(ans + 1)


import os
import sys
import math
import collections
import cmath

def mp():
	return map(int, input().split())

def inp():
	return input()
(n, t) = mp()
d = []
prev = 10000000
k = 0
for i in range(n):
	(a, b) = mp()
	k = a
	if b == 1 and a < t:
		k = t
	elif b == 1 and a >= t:
		k = a
	else:
		while k < t:
			k += b
	d.append(k)
c = min(d)
print(d.index(c) + 1)


(n, t) = map(int, input().split())
L = [list(map(int, input().split())) for i in range(n)]
L = list(map(lambda x: ((t - x[0] - 1) // x[1] + 1) * x[1] - (t - x[0]) if t >= x[0] else x[0] - t, L))
L = sorted(list(range(n)), key=lambda x: L[x])
print(L[0] + 1)


from math import ceil
(n, t) = map(int, input().split())
l = []
for i in range(n):
	(a, b) = map(int, input().split())
	l.append([a, b])
min = 10 ** 18
ans = 0
for i in range(n):
	if t >= l[i][0]:
		z = ceil((t - l[i][0]) / l[i][1]) + 1
		k = l[i][0] + (z - 1) * l[i][1]
	else:
		k = l[i][0]
	z1 = abs(t - k)
	if z1 < min:
		min = z1
		ans = i + 1
print(ans)


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mm = 1000000007

def solve():
	t = 1
	for it in range(t):
		(n, t) = num()
		xp = [0] * n
		ans = -1
		for i in range(n):
			(a, b) = num()
			if a >= t:
				xp[i] = a - t
			else:
				hp = t - a
				if hp % b == 0:
					xp[i] = a + hp // b * b - t
				else:
					xp[i] = a + (hp // b + 1) * b - t
		jp = min(xp)
		for i in range(n):
			if xp[i] == jp:
				ans = i + 1
				break
		print(ans)
solve()


import math
(n, t) = [int(x) for x in input().split()]
l = []
for case in range(n):
	l.append([int(x) for x in input().split()])
ans = 0
dif = 100000.0
for i in range(n):
	if t - l[i][0] <= 0:
		temp = l[i][0]
	else:
		temp = l[i][0] + math.ceil((t - l[i][0]) / l[i][1]) * l[i][1]
	if temp - t < dif:
		dif = temp - t
		ans = i
print(ans + 1)


(n, t) = input().split()
n = int(n)
t = int(t)
m = 10000000000000
for i in range(n):
	(a, b) = input().split()
	a = int(a)
	b = int(b)
	while a < t:
		a = a + b
	if a == t:
		index = i + 1
		break
	if a < m:
		index = i + 1
		m = a
print(index)


(n, t) = map(int, input().split())
mn = -1
for i in range(n):
	(s, d) = map(int, input().split())
	while s < t:
		s += d
	if mn == -1 or s - t < mn:
		mn = s - t
		ind = i + 1
print(ind)


(n, t) = map(int, input().strip().split())
later = [0 for i in range(n)]
bus = []
import heapq
for i in range(n):
	(s, d) = map(int, input().strip().split())
	later[i] = d
	heapq.heappush(bus, (s, i))
ans = 0
while True:
	result = heapq.heappop(bus)
	if result[0] >= t:
		ans = result[1]
		break
	else:
		first = 0
		last = 100000
		while first < last:
			mid = (first + last) // 2
			if result[0] + mid * later[result[1]] >= t:
				last = mid
			else:
				first = mid + 1
		heapq.heappush(bus, (result[0] + first * later[result[1]], result[1]))
print(ans + 1)


__author__ = 'Esfandiar'
from math import ceil
(n, t) = map(int, input().split())
M = 100000000000.0
for i in range(n):
	(s, d) = map(int, input().split())
	k = max(0, ceil((t - s) / d))
	yy = d * k + s
	if yy < M:
		M = yy
		bus = i + 1
print(bus)


from math import ceil
(n, t) = map(int, input().split())
buses = []
for _ in range(n):
	(s, d) = map(int, input().split())
	buses.append((s, d))
times = [(x[0], i + 1) if t <= x[0] else (x[0] + ceil((t - x[0]) / x[1]) * x[1], i + 1) for (i, x) in enumerate(buses)]
times.sort(key=lambda x: x[0])
print(times[0][1])


(n, t) = map(int, input().split())
ans = 0
mn = None
for _ in range(n):
	(s, d) = map(int, input().split())
	while s < t:
		s += d
	if mn == None or s < mn:
		mn = s
		ans = _
print(ans + 1)


def which_bus(arrival, times, intervals):
	(closest, idx) = (None, None)
	for i in range(len(times)):
		if times[i] == arrival:
			return i + 1
		elif times[i] > arrival:
			if closest is None or times[i] < closest:
				closest = times[i]
				idx = i + 1
		else:
			diff = arrival - times[i]
			if diff % intervals[i] == 0:
				time = times[i] + intervals[i] * (diff // intervals[i])
			else:
				time = times[i] + intervals[i] * (diff // intervals[i] + 1)
			if time == arrival:
				return i + 1
			if closest is None or time < closest:
				closest = time
				idx = i + 1
	return idx
(n, t) = list(map(int, input().split()))
(times, intervals) = ([], [])
for _ in range(n):
	(time, interval) = list(map(int, input().split()))
	times.append(time)
	intervals.append(interval)
print(which_bus(t, times, intervals))


import math
(n, t) = map(int, input().split())
ans = 0
mn = 1000000
ch = 0
for i in range(n):
	(s, d) = map(int, input().split())
	if not ch:
		if s - t == 0:
			mn = s
			ans = i + 1
			ch = 1
		elif s - t > 0 and s < mn:
			mn = s
			ans = i + 1
		elif s - t < 0:
			re = t - s
			temp = math.ceil(re / d)
			tot = temp * d + s
			if tot < mn:
				mn = tot
				ans = i + 1
print(ans)


(n, t) = map(int, input().split())
index = -1
dis = 10 ** 6
for i in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		start = s
	else:
		c = (t - s) // d + int((t - s) % d != 0)
		start = s + d * c
	if start < dis:
		index = i + 1
		dis = start
print(index)


import math

def solve(n, t, bus):
	res = float('inf')
	b = 1
	for i in range(n):
		(s, d) = bus[i]
		if s == t:
			return i + 1
		elif s < t:
			x = math.ceil((t - s) / d + 1)
			if s + (x - 1) * d < res:
				res = s + (x - 1) * d
				b = i + 1
		elif s > t:
			if res > s:
				res = s
				b = i + 1
	return b
(n, t) = map(int, input().split())
bus = []
for i in range(n):
	(s, d) = map(int, input().split())
	bus.append((s, d))
print(solve(n, t, bus))


import math
(n, t) = [int(i) for i in input().split()]
(s, d) = [int(j) for j in input().split()]
index = 1
if t <= s:
	mini = s - t
else:
	x = math.ceil((t - s) / d)
	mini = s + x * d - t
for i in range(2, n + 1):
	(s, d) = [int(j) for j in input().split()]
	if t <= s:
		y = s - t
	else:
		x = math.ceil((t - s) / d)
		y = s + x * d - t
	if y < mini:
		mini = y
		index = i
print(index)


(n, t) = map(int, input().split(' '))
arr1 = []
for _ in range(n):
	(s, d) = map(int, input().split(' '))
	diff = t - s
	if diff > 0:
		q = diff // d
		if diff % d == 0:
			s = s + q * d
		else:
			s = s + (q + 1) * d
	arr1.append(s)
val = arr1.index(min(arr1))
print(val + 1)


from math import ceil
(n, t) = map(int, input().split())
bus = []
for _ in range(n):
	(s, d) = map(int, input().split())
	if t <= s:
		bus.append(s)
	else:
		k = ceil((t - s) / d)
		temp = s + k * d
		bus.append(temp)
bust = bus[:]
bust.sort()
print(bus.index(bust[0]) + 1)


def solve():
	(N, T) = map(int, input().split())
	mn = 10 ** 10
	ans = -1
	for i in range(1, N + 1):
		(s, d) = map(int, input().split())
		if s == T:
			ans = i
			break
		while s < T:
			s += d
		wait = s - T
		if wait < mn:
			mn = wait
			ans = i
	print(ans)
solve()


(n, t) = map(int, input().split())
l = []
for i in range(n):
	(q, w) = map(int, input().split())
	if q <= t:
		n = (t - q + w - 1) // w
		l += [q + w * n - t]
	else:
		l += [q - t]
print(l.index(min(l)) + 1)


_DEBUG = True
(n, t) = map(int, input().split())
min_wait_time = float('inf')
min_wait_time_idx = None
for i in range(n):
	(s, d) = map(int, input().split())
	wait_time = None
	if t <= s:
		wait_time = s - t
	else:
		wait_time = (d - (t - s) % d) % d
	if wait_time < min_wait_time:
		min_wait_time = wait_time
		min_wait_time_idx = i
print(min_wait_time_idx + 1)


N_T = input().split()
N = int(N_T[0])
T = int(N_T[1])
import math
best = float('inf')
dict_bus = {}
for i in range(N):
	str_int = input().split()
	first = int(str_int[0])
	interval = int(str_int[1])
	if first >= T:
		time = first
	else:
		more = math.ceil((T - first) / interval)
		time = first + more * interval
	dict_bus[time] = i
	best = min(best, time)
print(dict_bus[best] + 1)


(n, t) = map(int, input().split())
(s, d) = ([0] * n, [0] * n)
p = [0] * n
for i in range(n):
	(s[i], d[i]) = map(int, input().split())
	while s[i] < t:
		s[i] += d[i]
print(s.index(min(s)) + 1)


from collections import defaultdict
from sys import stdin
from bisect import bisect_left as bl, bisect_right as br, insort
import heapq
from collections import deque
import math
(n, t) = list(map(int, input().split()))
a = []
for i in range(n):
	(c, d) = list(map(int, input().split()))
	if c < t:
		g2 = math.ceil((t - c) / d)
		a.append((c + g2 * d, i + 1))
	else:
		a.append((c, i + 1))
a.sort(key=lambda x: x[0])
print(a[0][1])


(n, t) = map(int, input().split())
l = []
route = []
for i in range(n):
	(s, d) = map(int, input().split())
	if s >= t:
		l.append(s)
		route.append(i + 1)
	else:
		l1 = list(range(s, t + d, d))
		l.append(l1[-1])
		route.append(i + 1)
print(route[l.index(min(l))])


(n, t) = map(int, input().split())
s = [None] * n
d = [None] * n
for i in range(n):
	(s[i], d[i]) = map(int, input().split())
earlyi = None
early = int(1000000000.0)
for i in range(n):
	earliest = s[i] + d[i] * max((t - s[i] + d[i] - 1) // d[i], 0)
	if earliest < early:
		earlyi = i
		early = earliest
print(earlyi + 1)


(n, t) = map(int, input().split())
mx = 1000000000
ans = -1
for i in range(n):
	(s, d) = map(int, input().split())
	nx = s + (t - s + d - 1) // d * d
	if s >= t:
		nx = s
	if nx < mx:
		mx = nx
		ans = i + 1
print(ans)


(n, t) = map(int, input().split())
buses = [tuple(map(int, input().split())) for _ in range(n)]

def waittime(bus):
	(s, d) = bus
	if t < s:
		return s - t
	k = (t - s + d - 1) // d
	return s + k * d - t
ans = min(range(n), key=lambda bus: waittime(buses[bus]))
print(ans + 1)


a = []
(n, t) = map(int, input().split())
for i in range(0, n):
	(d, s) = map(int, input().split())
	while d < t:
		d = d + s
		if d > t:
			break
	wait = d - t
	a.append(wait)
route = 1 + int(a.index(min(a)))
print(route)


import sys
(n, t) = map(int, sys.stdin.readline().split(' '))
buses = []
best_wait = 10 ** 12
best_bus = -1
for i in range(n):
	(s, d) = map(int, sys.stdin.readline().split(' '))
	if s < t:
		(mod, div) = ((t - s) % d, (t - s) // d)
		if mod != 0:
			div = div + 1
		arrival = s + d * div
		wait_time = arrival - t
		if wait_time < best_wait:
			best_wait = wait_time
			best_bus = i
	else:
		wait_time = s - t
		if wait_time < best_wait:
			best_wait = wait_time
			best_bus = i
print(best_bus + 1)


(n, t) = list(map(int, input().split()))
diff = {}
for i in range(1, n + 1):
	(s, d) = list(map(int, input().split()))
	if t <= s:
		diff[i] = s - t
	else:
		x = (t - s) // d
		if (t - s) % d != 0:
			x += 1
		s += x * d
		diff[i] = s - t
diff_sort = sorted(diff.items(), key=lambda x: x[1])
print(diff_sort[0][0])


def calc_route():
	(n, t) = map(int, input().split())
	schedule = []
	for _ in range(n):
		schedule.append(tuple(map(int, input().split())))
	difference = []
	for (i, (time, interval)) in enumerate(schedule):
		start = t - time
		if start == 0:
			return i + 1
		if start < 0:
			difference.append((-start, i + 1))
		elif start <= interval:
			difference.append((interval - start, i + 1))
		else:
			diff = start % interval
			difference.append((diff if diff == 0 else interval - diff, i + 1))
	difference.sort()
	return difference[0][1]
print(calc_route())


def search():
	(n, t) = map(int, input().split())
	frs = [0] * n
	delta = [0] * n
	min_i = -1
	for i in range(n):
		(frs[i], delta[i]) = map(int, input().split())
	time_lst = [-1] * n
	wait_time = 0
	for i in range(n):
		wait_time = frs[i] - t
		if wait_time == 0:
			return i + 1
		while wait_time < 0:
			wait_time += delta[i]
			if wait_time == 0:
				return i + 1
		time_lst[i] = wait_time
	res = time_lst.index(min(time_lst)) + 1
	return res
print(search())


(a, b) = [int(i) for i in input().split()]
l = []
for _ in range(a):
	(c, d) = [int(i) for i in input().split()]
	sum = c
	while sum < b:
		sum = sum + d
	l.append(sum)
print(l.index(min(l)) + 1)


from math import ceil
(n, t) = tuple(map(int, input().split()))
li = [(0, 0)] * n
for i in range(n):
	(s, d) = tuple(map(int, input().split()))
	diff = t - s
	x = int(ceil(diff / d))
	li[i] = (s + d * x if diff >= 0 else s, i)
print(sorted(li)[0][1] + 1)


(n, m) = map(int, input().split())
d = []
for i in range(n):
	(a, b) = map(int, input().split())
	while a < m:
		a += b
	d.append(a)
print(d.index(min(d)) + 1)


from math import ceil
(n, t) = map(int, input().split())
a = []
b = []
for i in range(n):
	(u, v) = map(int, input().split())
	a.append(u)
	b.append(v)
w = 10 ** 9
bo = 0
bus = 0
for (i, j) in zip(a, b):
	bus += 1
	if t > i:
		k = int((t - i) / j)
		if k < (t - i) / j:
			k += 1
		k = i + j * k
	else:
		k = i
	if w > k - t:
		w = k - t
		bo = bus
print(bo)


(n, t) = map(int, input().split())
a = []
import math
for i in range(n):
	(r, d) = map(int, input().split())
	if r < t:
		r = r + math.ceil((t - r) / d) * d
	a.append(r)
s = a[0] - t
k = 0
for i in range(1, n):
	if a[i] - t < s:
		s = a[i] - t
		k = i
print(k + 1)


import sys
import math
import bisect

def solve(A):
	n = len(A)
	min_val = min(A)
	for i in range(n):
		if A[i] == min_val:
			return i
	return -1

def main():
	(n, m) = map(int, input().split())
	A = [0] * n
	for i in range(n):
		(start, period) = map(int, input().split())
		A[i] = start
		while A[i] < m:
			A[i] += period
	print(solve(A) + 1)
main()


(n, t) = map(int, input().split())
ans = (10 ** 9, 0)
for i in range(n):
	(a, b) = map(int, input().split())
	val = 0
	if a >= t:
		val = a
	else:
		val = a + (t - a + b - 1) // b * b
	if ans[0] > val:
		ans = (val, i + 1)
print(ans[1])


from math import ceil as ce
(n, t) = [int(i) for i in input().split()]
ans = 10 ** 9
num = 0
for I in range(n):
	(s, d) = [int(i) for i in input().split()]
	k = max(1, ce((t - s + d) / d))
	time = s + (k - 1) * d
	if time - t < ans:
		ans = time - t
		num = I + 1
print(num)


import math
(n, t) = map(int, input().split(' '))
l = []
for i in range(n):
	(s, d) = map(int, input().split(' '))
	l.append([s, d])
pp = [max(math.ceil((t - l[i][0]) / l[i][1]), 0) * l[i][1] + l[i][0] - t for i in range(n)]
print(pp.index(min(pp)) + 1)


import sys

def input():
	return sys.stdin.readline().strip()

def print(*x, sep=' ', end='\n'):
	return sys.stdout.write(sep.join(map(str, x)) + end)

def read():
	return sys.stdin.read()

def get():
	return map(int, input().split())

def out(*arg):
	if type(arg[0]) == list:
		for i in arg[0]:
			print(i)
	else:
		print(arg)

def main():
	from math import ceil
	(n, t) = get()
	ans = []
	for i in range(n):
		(s, d) = get()
		if s < t:
			s = s + d * ceil((t - s) / d)
		ans.append((s, d, i + 1))
	ans.sort(key=lambda x: (x[0], x[1]))
	print(ans[0][2])
main()


(n, t) = map(int, input().split())

def the_res(val, p):
	if val >= t:
		res = val - t
	else:
		temp = t - val
		if temp % p:
			temp = temp // p + 1
		else:
			temp = temp // p
		res = val - t + temp * p
	return res
val = 0
p = 0
res = 0
minn = 1000000000
pos = -1
for i in range(n):
	(val, p) = map(int, input().split())
	if the_res(val, p) < minn:
		pos = i + 1
		minn = the_res(val, p)
print(pos)


(n, t) = map(int, input().split())
s = 300000
n1 = 1
for i in range(n):
	(a, b) = map(int, input().split())
	k = a
	if k < t:
		if (t - a) % b == 0:
			k = t
		else:
			k = k + ((t - a) // b + 1) * b
	if k < s:
		s = k
		n1 = i + 1
print(n1)


(n, t) = input().split()
n = int(n)
t = int(t)
r1 = 0
r2 = 0
for i in range(n):
	(s, d) = input().split()
	s = int(s)
	d = int(d)
	while s < t:
		s += d
	if r1 == 0:
		r2 = s
		r1 = i + 1
	if s == t:
		r1 = i + 1
		while i < n - 1:
			(a, b) = input().split()
			i += 1
		break
	elif s > t:
		if s < r2:
			r2 = s
			r1 = i + 1
print(r1)


(N, T) = map(int, input().split())
f_ls = [0] * N

def db(*arg):
	print(*arg)
for i in range(N):
	(s, d) = map(int, input().split())
	if s >= T:
		f_ls[i] = s
	else:
		bus_times = -(-(T - s) // d)
		f_ls[i] = s + d * bus_times
fastest_time = float('inf')
ans = -1
for i in range(N):
	if f_ls[i] <= fastest_time:
		ans = i + 1
		fastest_time = f_ls[i]
print(ans)


import sys
import functools
import itertools
import os
import math

def redirect_input_from_file():
	read_f = open('input.txt', 'r').readlines()

	def read_ff(prompt=''):
		return read_f.pop(0).strip()
	return read_ff

def redirect_output_to_file():
	write_f = open('output.txt', 'w')

	def write_ff(*args, sep=' ', end='\n', stop=False):
		if stop:
			write_f.close()
		else:
			print(*args, sep=sep, end=end, file=write_f)
	return write_ff

def memoize(function):
	memo = {}

	@functools.wraps(function)
	def f(*args):
		parsed_args = args
		parsed_args = []
		for arg in args:
			if type(arg) is list or type(arg) is set:
				arg = tuple(sorted(arg))
			parsed_args.append(arg)
		parsed_args = tuple(parsed_args)
		if parsed_args not in memo:
			memo[parsed_args] = function(*args)
			if not len(memo) & 32767:
				print('memoization limit exceeded({}) for function {}'.format(len(memo), function.__name__), file=sys.stderr)
		return memo[parsed_args]
	f.memo = memo
	return f

def input_one(f=int):
	return f(input().strip())

def input_row(f=int):
	return list(map(f, input_one(str).split()))

def input_column(n, f=int):
	return [input_one(f) for _ in range(n)]

def input_grid(n, f=int):
	return [input_row(f) for _ in range(n)]

def testcases():
	return range(1, int(input().strip()) + 1)

def solve():
	(n, t) = input_row()
	busses = input_grid(n)

	def minT(a, d):
		if a > t:
			T = a
		else:
			v = (t - a) / d
			best_v = math.ceil(v)
			T = d * best_v + a
		return T
	v = min(busses, key=lambda x: minT(*x))
	return busses.index(v) + 1
print_out = print
print(solve())


r = list(map(int, input().split()))
n = r[0]
t = r[1]
s = []
d = []
for i in range(n):
	e = list(map(int, input().split()))
	s.append(e[0])
	d.append(e[1])
end = False
for j in range(len(s)):
	if s[j] == t or ((t - s[j]) % d[j] == 0 and (t - s[j]) / d[j] > 0):
		print(j + 1)
		end = True
		break
if t not in s and end == False:
	x = []
	for i in range(len(s)):
		if s[i] - t > 0:
			x.append(s[i] - t)
		elif s[i] - t < 0:
			while s[i] - t < 0:
				s[i] = s[i] + d[i]
			s[i] = s[i] - t
			x.append(s[i])
	m = x.index(min(x))
	print(m + 1)