Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.

Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.

What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".


-----Input-----

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000).

The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.


-----Output-----

If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.


-----Examples-----
Input
3
-7 1
5 2
8 2

Output
1907

Input
2
57 1
22 2

Output
Impossible

Input
1
-5 1

Output
Infinity

Input
4
27 2
13 1
-50 1
8 2

Output
1897



-----Note-----

In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating:  Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7.  With rating 1894 Limak is in the division 2. His rating increases by 5.  Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets  + 8 and ends the year with rating 1907. 

In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.

Difficulty: MEDIUM_HARD
Tags: Sorting

Mathematics

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
s = 0
a = b = ''
for i in range(int(input())):
	(c, d) = map(int, input().split())
	if d == 1:
		a = min(a, s) if a != '' else s
	else:
		b = max(b, s) if b != '' else s
	s += c
print('Infinity' if b == '' else 'Impossible' if a != '' and a - b < 1 else 1899 - b + s)


q = int(input())
q -= 1
(a, s) = map(int, input().split())
if s == 1:
	z = 1900
	x = 9000000000
else:
	z = -9000000000
	x = 1899
z += a
x += a
for j in range(0, q):
	(a, s) = map(int, input().split())
	if s == 1:
		z = max(1900, z)
	else:
		x = min(1899, x)
	z += a
	x += a
if x < z:
	print('Impossible')
elif x >= 7000000000:
	print('Infinity')
else:
	print(x)


n = int(input())
mx = 10 ** 9
mn = -mx
p = 0
for i in range(n):
	(c, d) = [int(i) for i in input().split()]
	if d == 1:
		mn = max(mn, 1900 - p)
	else:
		mx = min(mx, 1899 - p)
	p += c
if mx == 10 ** 9:
	print('Infinity')
elif mx >= mn:
	print(mx + p)
else:
	print('Impossible')


import math
k = int(input())
up = 1000000000000000000000000000000000000000000000000000000000000000000000
down = -1 * up
inf = 0
(a, b) = map(int, input().split())
if b == 2:
	up = 1899 + a
	inf = 1
	down += a
else:
	down = 1900 + a
ok = 0
for i in range(k - 1):
	(a, b) = map(int, input().split())
	if b == 2:
		if up > 1899:
			inf = 1
			up = 1899
		if down > 1899:
			ok = 1
			break
		up += a
		down += a
	else:
		if up < 1900:
			ok = 1
			break
		if down < 1900:
			down = 1900
		up += a
		down += a
if inf == 0 and ok == 0:
	ok = 1
	print('Infinity')
elif ok == 0:
	print(up)
else:
	print('Impossible')


def check(rating):
	r = rating
	for i in l:
		if rating <= 1899 and i[1] == 1:
			return '1'
		if rating >= 1900 and i[1] == 2:
			return '2'
		rating += i[0]
	nl.append(rating)
	return '1'
n = int(input())
seen = set()
l = []
for i in range(n):
	(c, d) = map(int, input().split())
	seen.add(d)
	l.append([c, d])
nl = []
if len(seen) == 1 and 1 in seen:
	print('Infinity')
else:
	s = 0
	f = 0
	onemin = float('inf')
	twomax = float('-inf')
	for i in l:
		if i[1] == 1:
			if s <= twomax:
				f = 1
				break
			onemin = min(onemin, s)
		else:
			if s >= onemin:
				f = 1
				break
			twomax = max(twomax, s)
		s += i[0]
	if f == 1:
		print('Impossible')
	else:
		if l[0][1] == 1:
			start = 1900
			end = 2 * 10 ** 7 + 1900
		else:
			start = -(2 * 10 ** 7 + 1900)
			end = 1899
		while start <= end:
			mid = (start + end) // 2
			ck = check(mid)
			if ck == '1':
				start = mid + 1
			else:
				end = mid - 1
		print(max(nl))


import sys
import math
import collections
import heapq
import decimal
input = sys.stdin.readline
n = int(input())
ma = 1000000000
mi = -1000000000
k = 0
for i in range(n):
	(c, d) = (int(j) for j in input().split())
	if d == 1:
		mi = max(mi, 1900 - k)
	else:
		ma = min(ma, 1899 - k)
	k += c
if ma == 1000000000:
	print('Infinity')
elif mi > ma:
	print('Impossible')
else:
	print(ma + k)


from collections import defaultdict
import sys, os, math
n = int(input())
(l, r) = (-200000000, 200000000)
temp = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if b == 1:
		l = max(1900 - temp, l)
	else:
		r = min(1900 - temp, r)
	temp += a
if r == 200000000:
	print('Infinity')
elif l >= r:
	print('Impossible')
else:
	print(temp + r - 1)


n = int(input())
(c, div) = map(int, input().split())
if div == 1:
	x = None
	y = 1900
else:
	x = 1899
	y = None
proof = True
for i in range(n - 1):
	if x != None:
		x += c
	if y != None:
		y += c
	(c, div) = map(int, input().split())
	if div == 1:
		if x != None and x < 1900:
			proof = False
		elif y == None:
			y = 1900
		else:
			y = max(y, 1900)
	elif y != None and y > 1899:
		proof = False
	elif x == None:
		x = 1899
	else:
		x = min(x, 1899)
if proof:
	if x == None:
		print('Infinity')
	else:
		print(x + c)
else:
	print('Impossible')


from math import inf

def main():
	n = int(input())
	l = -inf
	r = inf
	for i in range(n):
		(c, d) = map(int, input().split())
		if d == 1:
			l = max(1900, l)
		else:
			r = min(1899, r)
		if l > r:
			print('Impossible')
			return
		l += c
		r += c
	if r == inf:
		print('Infinity')
	else:
		print(r)
main()


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

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

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(int, input().split())
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
l = -int(10000000000.0)
r = int(10000000000.0)
div = 3
for _ in range(n):
	(c, d) = mapin()
	if d == 1:
		if div == 3:
			div = 1
		l = max(l, 1900)
	else:
		div = 4
		r = min(r, 1899)
	if l > r:
		print('Impossible')
		exit()
	l = l + c
	r = r + c
if div == 1:
	print('Infinity')
else:
	print(r)


n = int(input())
INF = 10 ** 9
(emax, emin) = (INF, -INF)
for _ in range(n):
	(c, d) = map(int, input().split())
	if d == 1:
		emin = max(emin, 1900)
	elif d == 2:
		emax = min(emax, 1899)
	emin += c
	emax += c
if emin > emax:
	print('Impossible')
elif emax >= INF / 2:
	print('Infinity')
else:
	print(emax)


n = int(input())
dirs = []
for x in range(0, n):
	line = input().split()
	dirs.append([int(line[0]), int(line[1])])
pre = 0
L = -200000000
R = 200000000
for dir in dirs:
	if dir[1] == 1:
		L = max(L, 1900 - pre)
	else:
		R = min(R, 1899 - pre)
	pre = pre + dir[0]
if L > R:
	print('Impossible')
elif L <= R and R == 200000000:
	print('Infinity')
else:
	print(pre + R)


n = int(input())
for i in range(n):
	(change, division) = input().split()
	change = int(change)
	division = int(division)
	if i == 0:
		if division == 1:
			maxx = 10 ** 15
			minn = 1900
		else:
			maxx = 1899
			minn = -10 ** 10
	if division == 1:
		if maxx < 1900:
			print('Impossible')
			return
		minn = max(minn, 1900)
		minn = minn + change
		maxx = maxx + change
	else:
		if minn >= 1900:
			print('Impossible')
			return
		maxx = min(maxx, 1899)
		minn = minn + change
		maxx = maxx + change
if maxx > 10 ** 10:
	print('Infinity')
else:
	print(maxx)


import sys
from numbers import Integral
div2_max_rate = 1899

def main():
	n = int(sys.stdin.readline().strip())
	(c_list, d_list) = ([], [])
	rates = []
	for i in range(n):
		(c, d) = [int(s) for s in sys.stdin.readline().split()]
		if i == 0:
			rates.append(0)
		else:
			rates.append(rates[-1] + c_list[-1])
		c_list.append(c)
		d_list.append(d)
	rates.append(rates[-1] + c_list[-1])
	for i in range(n - 1):
		c = c_list[i]
		d = d_list[i]
		d_n = d_list[i + 1]
		impossible = False
		if c * (d_n - d) > 0:
			impossible = True
		if c == 0 and d_n != d:
			impossible = True
		if impossible:
			print('Impossible')
			return
	mx_rate = None
	for (r, d) in zip(rates, d_list):
		if d == 2:
			if mx_rate is None:
				mx_rate = r
			else:
				mx_rate = max(mx_rate, r)
	if mx_rate is None:
		print('Infinity')
		return
	d = div2_max_rate - mx_rate
	rates = [r + d for r in rates]
	impossible = False
	for (r, d) in zip(rates, d_list):
		if r > div2_max_rate and d == 2:
			impossible = True
		if r <= div2_max_rate and d == 1:
			impossible = True
		if impossible:
			print('Impossible')
			return
	print(rates[-1])
main()


n = int(input())
A = [0] * n
per = 0
ans1 = float('infinity')
ans2 = -float('infinity')
for j in range(n):
	(per1, per2) = map(int, input().split())
	if per2 == 1:
		if ans1 < 1900:
			per = 1
			break
		else:
			ans2 = max(ans2, 1900)
			ans1 += per1
			ans2 += per1
	elif ans2 >= 1900:
		per = 1
		break
	else:
		ans1 = min(ans1, 1899)
		ans1 += per1
		ans2 += per1
	if ans1 < ans2:
		per = 1
		break
if per == 0:
	if ans1 == float('infinity'):
		print('Infinity')
	else:
		print(ans1)
else:
	print('Impossible')


num_contests = int(input())
rating = 0
upper_bound = None
lower_bound = None
for contest_num in range(num_contests):
	(ci, di) = map(int, input().split())
	if di == 1:
		if upper_bound is None or rating < upper_bound:
			upper_bound = rating
	else:
		assert di == 2
		if lower_bound is None or rating > lower_bound:
			lower_bound = rating
	rating += ci
if lower_bound is None:
	print('Infinity')
elif upper_bound is not None and lower_bound >= upper_bound:
	print('Impossible')
else:
	print(rating - (lower_bound + 1) + 1900)


I = lambda : list(map(int, input().split()))
n = I()[0]
(c, d) = [[0] * n for _ in range(2)]
for i in range(n):
	(_c, _d) = I()
	c[i] = _c
	d[i] = _d
(lb, ub, change) = (-1e+100, 1e+100, 0)
for i in range(n)[::-1]:
	change -= c[i]
	if d[i] == 1:
		lb = max(lb, 1900 - change)
	else:
		ub = min(ub, 1899 - change)
	if lb > ub:
		print('Impossible')
		break
if ub == 1e+100:
	print('Infinity')
elif lb <= ub:
	print(ub)


def main():
	n = int(input())
	mn = -int(2000000000.0)
	mx = int(2000000000.0)
	impossible = False
	for i in range(n):
		(c, d) = [int(_) for _ in input().split()]
		if d == 1 and mx < 1900 or (d == 2 and mn > 1899):
			impossible = True
			break
		if d == 1:
			mn = max(mn, 1900)
		else:
			mx = min(mx, 1899)
		mn += c
		mx += c
		if mn > mx:
			impossible = True
			break
	if impossible:
		print('Impossible')
	elif mx > 1000000000.0:
		print('Infinity')
	else:
		print(mx)
main()


FIRST_DIV_START = 1900

def solve():
	n = int(input())
	min_rating = None
	max_rating = None
	for _ in range(n):
		(c, d) = list(map(int, input().split()))
		if d == 2:
			if max_rating is None:
				max_rating = FIRST_DIV_START - 1
			else:
				max_rating = min(FIRST_DIV_START - 1, max_rating)
			if min_rating is not None and min_rating > max_rating:
				return 'Impossible'
			max_rating += c
			if min_rating is not None:
				min_rating += c
		else:
			if min_rating is None:
				min_rating = FIRST_DIV_START
			else:
				min_rating = max(min_rating, FIRST_DIV_START)
			if max_rating is not None and min_rating > max_rating:
				return 'Impossible'
			min_rating += c
			if max_rating is not None:
				max_rating += c
	if max_rating is None:
		return 'Infinity'
	return max_rating

def __starting_point():
	print(solve())
__starting_point()


n = int(input())
inf = 1000000000.0
minn = -inf
maxx = inf
for i in range(n):
	(c, d) = map(int, input().split())
	if d == 1:
		minn = max(1900, minn)
	else:
		maxx = min(1899, maxx)
	minn += c
	maxx += c
if minn > maxx:
	print('Impossible')
elif maxx > inf / 4:
	print('Infinity')
else:
	print(maxx)


n = int(input())
cdi = [[0, 0]] + [list(map(int, input().split())) for i in range(n)]
for i in range(1, n + 1):
	cdi[i][0] += cdi[i - 1][0]
	cdi[i - 1][1] = cdi[i][1]
cdi[-1][1] = 3
maxi = -10 ** 9
mini = 10 ** 9
for i in range(n):
	if cdi[i][1] == 1:
		mini = min(mini, cdi[i][0])
	else:
		maxi = max(maxi, cdi[i][0])
if maxi >= mini:
	print('Impossible')
elif maxi == -10 ** 9:
	print('Infinity')
else:
	print(1899 - maxi + cdi[-1][0])


from sys import *
n = int(stdin.readline())
INF = 100000000000000000000000
MAX = 2 * INF
MIN = -MAX
possible = True
for _ in range(n):
	(c, d) = stdin.readline().split(' ')
	c = int(c)
	d = int(d)
	if d is 1:
		MIN = max(MIN, 1900)
	if d is 2:
		MAX = min(MAX, 1899)
	if MIN > MAX:
		possible = False
	MIN += c
	MAX += c
if not possible:
	print('Impossible')
elif MAX > INF:
	print('Infinity')
else:
	print(MAX)


n = int(input())
s = 10 ** 10
x = s
K = 1900
p = []
for i in range(n):
	(c, d) = map(int, input().split())
	p.append([c, d])
	if x >= K and d == 2:
		s -= x - (K - 1)
		x = K - 1
	elif x < K and d == 1:
		s += K - x
		x = K
	x += c
x = s
ok = True
for i in range(n):
	(c, d) = p[i]
	if (x < K) + 1 != d:
		ok = False
	x += c
if not ok:
	print('Impossible')
elif x > 10 ** 9:
	print('Infinity')
else:
	print(x)


k = 9 ** 9
t = [0, k, k]
for i in range(int(input())):
	(c, d) = map(int, input().split())
	d = 3 - 2 * d
	t[d] = min(t[d], t[0] * d)
	t[0] += c
(s, a, b) = t
print('Infinity' if b == k else 'Impossible' if a != k and a + b < 1 else 1899 + s + b)


n = int(input())
r = 0
xmin = -10 ** 8
xmax = 10 ** 8
infin = 1
(c, d) = [int(t) for t in input().split(' ')]
if d == 2:
	xmax = 1899
	infin = 0
else:
	xmin = 1900
for i in range(n - 1):
	c0 = c
	d0 = d
	(c, d) = [int(t) for t in input().split(' ')]
	xmax += c0
	xmin += c0
	if d == 2:
		xmax = min(xmax, 1899)
		infin = 0
	else:
		xmin = max(xmin, 1900)
	if c0 == 0 and d != d0:
		r = -1
	if xmax < xmin:
		r = -1
if r == -1:
	print('Impossible')
elif xmax >= 10 ** 8 or infin == 1:
	print('Infinity')
else:
	print(xmax + c)


n = int(input())
l = -1000000000000000.0
r = 1000000000000000.0
c = list(range(n))
d = list(range(n))
s = list(range(n))
for i in range(n):
	(c[i], d[i]) = map(int, input().split())
	if i > 0:
		s[i] = s[i - 1] + c[i - 1]
		if d[i] == 1:
			l = max(1900 - s[i], l)
		else:
			r = min(1899 - s[i], r)
	if r < l:
		print('Impossible')
		quit()
if d[0] == 1:
	l = max(1900, l)
else:
	r = min(1899, r)
if r < l:
	print('Impossible')
elif r == 1000000000000000.0:
	print('Infinity')
else:
	print(r + s[n - 1] + c[n - 1])


n = int(input())
max_r = float('inf')
min_r = -max_r
for i in range(0, n):
	(x, y) = input().split()
	(x, y) = (int(x), int(y))
	if i == 0:
		if y == 1:
			min_r = 1900
		else:
			max_r = 1899
	else:
		if y == 1 and max_r < 1900:
			print('Impossible')
			exit()
		elif y == 1:
			min_r = max(1900, min_r)
		if y == 2 and min_r > 1899:
			print('Impossible')
			exit()
		elif y == 2:
			max_r = min(1899, max_r)
	min_r = min_r + x
	max_r = max_r + x
if max_r == float('inf'):
	print('Infinity')
else:
	print(max_r)


n = int(input())
(firstT, firstB) = (True, True)
t = 1
b = 0
x = 0
for i in range(n):
	(c, d) = map(int, input().split())
	if d == 1:
		if firstB:
			b = 1900 - x
			firstB = False
		b = max(b, 1900 - x)
	else:
		if firstT:
			t = 1900 - x
			firstT = False
		t = min(t, 1900 - x)
	x += c
if firstT:
	print('Infinity')
elif not firstB and b >= t:
	print('Impossible')
else:
	print(t - 1 + x)


import sys
sys.setrecursionlimit(5000000)

def read(type=int):
	return type(input())

def read_arr(type=int):
	return [type(token) for token in input().split()]

def abs(num):
	return num if num > 0 else -num
inf = 10 ** 9
c = 1899
(u, l) = (inf, -inf)
diff = 0
n = read()
A = []
for i in range(n):
	(r, d) = read_arr()
	A.append((r, d))
e = False
for (r, d) in A:
	if d == 1:
		l = max(l, 1900 - diff)
	else:
		u = min(u, 1899 - diff)
	diff += r
	if u < l:
		e = True
		break
if e or l > u:
	print('Impossible')
elif u == inf:
	print('Infinity')
else:
	print(u + diff)


import sys

def Main(n):
	(mn, mx) = (-10 ** 18, 10 ** 18)
	for _ in range(n):
		(c, d) = map(int, input().split())
		if d == 1:
			mn = max(mn, 1900)
		else:
			mx = min(mx, 1899)
		mn += c
		mx += c
	if mn > mx:
		print('Impossible')
		return 0
	if mx > 10 ** 17:
		print('Infinity')
		return 0
	print(mx)
n = int(input())
Main(n)


import sys
import math

def solve():
	n = int(input())
	(l, r) = (-float('inf'), float('inf'))
	for line in sys.stdin:
		(c, d) = map(int, line.split())
		if d == 1:
			l = max(1900, l)
		else:
			r = min(1899, r)
		l += c
		r += c
	if r < l:
		return None
	else:
		return r
res = solve()
if res is None:
	print('Impossible')
elif math.isinf(res):
	print('Infinity')
else:
	print(res)


n = int(input())
t = 0
d1 = +30000000
d2 = -30000000
for i in range(n):
	(k, d) = map(int, input().split())
	if d == 2:
		d2 = max(d2, t)
	else:
		d1 = min(d1, t)
	t += k
if d1 <= d2:
	print('Impossible')
elif d2 == -30000000:
	print('Infinity')
else:
	print(1899 - d2 + t)


def main():
	try:
		while True:
			n = int(input())
			c = [0] * n
			d = [0] * n
			has_2 = False
			for i in range(n):
				(c[i], d[i]) = map(int, input().split())
				if d[i] == 2:
					has_2 = True
			if not has_2:
				print('Infinity')
				continue
			minr = -10 ** 9
			maxr = 10 ** 9
			for i in range(n):
				if d[i] == 1:
					minr = max(minr, 1900)
				else:
					maxr = min(maxr, 1899)
				if minr > maxr:
					print('Impossible')
					break
				minr += c[i]
				maxr += c[i]
			else:
				print(maxr)
	except EOFError:
		pass
main()


ans = 0
check1 = -9999999999
check2 = 9999999999
for i in range(int(input())):
	(a, b) = map(int, input().split())
	if b == 1:
		if check2 < 1900:
			print('Impossible')
			exit()
		check1 = max(check1, 1900) + a
		check2 += a
	else:
		if check1 >= 1900:
			print('Impossible')
			exit()
		check2 = min(check2, 1899) + a
		check1 += a
print('Infinity' if check2 >= 9979999999 else check2)


n = int(input())
l = [[0, 0] for i in range(n + 1)]
for i in range(n):
	if i == 0:
		l.append([0, 0])
	(a, b) = list(map(int, input().split()))
	l[i + 1][0] += l[i][0] + a
	l[i][1] = b

def search(x):
	for i in range(n):
		if l[i][1] == 2 and x > 1899 - l[i][0]:
			return 's'
		if l[i][1] == 1 and x < 1900 - l[i][0]:
			return 'b'
	return 'ok'
uk1 = -1000000000
uk2 = 1000000000
mb = False
for i in range(n):
	if l[i][1] == 2:
		mb = True
if not mb:
	print('Infinity')
	exit()
while uk2 - uk1 > 1:
	mac = (uk2 + uk1) // 2
	if search(mac) == 's':
		uk2 = mac
	else:
		uk1 = mac
if search(uk1) == 'ok':
	print(uk1 + l[-2][0])
else:
	print('Impossible')


n = int(input())
rounds = [[*map(int, input().split())] for _ in range(n)]
ans = -1

def check(m):
	d = int()
	for (i, j) in rounds:
		d = 2 if m < 1900 else 1
		if d != j:
			if d == 2:
				return 0
			else:
				return -1
		m += i
	global ans
	ans = m
	return 1

def binsearch(l, r):
	while l < r:
		m = (l + r + 1) // 2
		if check(m) == -1:
			r = m - 1
		elif check(m) == 0:
			l = m + 1
		else:
			l = m
	return l
if all((i[1] == 1 for i in rounds)):
	print('Infinity')
else:
	v = binsearch(int(-100000000.0), int(100000000.0))
	print(ans if check(v) == 1 else 'Impossible')


n = int(input())
c = [0 for i in range(n)]
(c[0], d) = map(int, input().split())
INF = 1000000000.0
a = -INF
b = INF
if d == 1:
	a = 1900
else:
	b = 1899
s = 0
for i in range(1, n):
	(c[i], d) = map(int, input().split())
	s += c[i - 1]
	if d == 1:
		a = max(1900 - s, a)
	else:
		b = min(1899 - s, b)
s += c[n - 1]
if b == INF:
	print('Infinity')
elif a > b:
	print('Impossible')
else:
	print(b + s)


INF = float('inf')
n = int(input())
dp1 = [0 for _ in range(n + 1)]
dp2 = [0 for _ in range(n + 1)]
d = list()
c = list()
for _ in range(n):
	(x, y) = map(int, input().split())
	c.append(x)
	d.append(y)
if d[0] == 1:
	dp1[0] = 1900
	dp2[0] = INF
else:
	dp1[0] = -INF
	dp2[0] = 1899
impossible = False
for i in range(1, n):
	if d[i - 1] == 1 and d[i] == 1:
		dp1[i] = max(1900, dp1[i - 1] + c[i - 1])
		dp2[i] = dp2[i - 1] + c[i - 1]
	elif d[i - 1] == 2 and d[i] == 2:
		dp1[i] = dp1[i - 1] + c[i - 1]
		dp2[i] = min(1899, dp2[i - 1] + c[i - 1])
	elif d[i - 1] == 1 and d[i] == 2:
		dp1[i] = max(1899 + c[i - 1], dp1[i - 1] + c[i - 1])
		dp2[i] = min(1899, dp2[i - 1] + c[i - 1])
	elif d[i - 1] == 2 and d[i] == 1:
		dp1[i] = max(1900, dp1[i - 1] + c[i - 1])
		dp2[i] = dp2[i - 1] + c[i - 1]
	if dp1[i] > dp2[i]:
		impossible = True
dp2[n] = dp2[n - 1] + c[n - 1]
if impossible:
	print('Impossible')
elif dp2[n] == INF:
	print('Infinity')
else:
	print(dp2[n])


import math
n = int(input())
(c, d) = ([], [])
no = False
for _ in range(0, n):
	string = list(map(int, input().split()))
	c.append(string[0])
	d.append(string[1])
if all([x == 1 for x in d]):
	print('Infinity')
elif n == 1:
	print(1899 + c[0])
else:
	if d[0] == 1:
		x = (1900, math.inf)
	else:
		x = (-math.inf, 1899)
	div = d[0]
	for i in range(0, n - 1):
		x_next = x
		if d[i] == 1 and d[i + 1] == 2:
			x_next = (x[0] + c[i], min(1899, x[1] + c[i]))
		elif d[i] == 2 and d[i + 1] == 1:
			x_next = (max(1900, x[0] + c[i]), x[1] + c[i])
		else:
			x_next = (max(x[0] + c[i], 1900) if d[i + 1] == 1 else x[0] + c[i], min(x[1] + c[i], 1899) if d[i + 1] == 2 else x[1] + c[i])
		if x_next[0] > x_next[1]:
			no = True
			break
		else:
			x = x_next
	print('Impossible' if no else x[1] + c[-1])


from sys import stdin

def main():
	input()
	(mi, ma) = (-10 ** 9, 10 ** 9)
	for s in stdin.read().splitlines():
		(c, d) = map(int, s.split())
		if d == 1:
			if mi < 1900:
				mi = 1900
		elif ma > 1899:
			ma = 1899
		if mi > ma:
			print('Impossible')
			return
		mi += c
		ma += c
	print(ma if ma < 10 ** 8 else 'Infinity')
main()


from __future__ import print_function
from itertools import permutations as perm
from collections import *
from sys import stdin
from bisect import *
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n,) = gil()
max_rating = -inf
min_rating = inf
(div, rat) = ([1] * n, [0] * (n + 1))
rat[0] = 1900
for i in range(n):
	(delta, divi) = gil()
	div[i] = divi
	if divi == 2:
		max_rating = max(max_rating, rat[i])
	else:
		min_rating = min(min_rating, rat[i])
	rat[i + 1] = rat[i] + delta
if max_rating == -inf:
	print('Infinity')
else:
	delta = 1899 - max_rating
	if min_rating + delta >= 1900:
		print(rat[-1] + delta)
	else:
		print('Impossible')


n = int(input())
mx = 5 * 10 ** 9
mn = -10 ** 9
flag = True
for i in range(n):
	(c, d) = map(int, input().split())
	if d == 1:
		mn = max(mn, 1900)
	else:
		mx = min(mx, 1899)
	if mn > mx:
		flag = False
	mn += c
	mx += c
if not flag:
	print('Impossible')
elif mx > 10 ** 9:
	print('Infinity')
else:
	print(mx)


inf = float('inf')

def solve(c, d):
	l = -inf
	h = inf
	for i in range(n):
		if d[i] == 1:
			l = max(1900, l)
		else:
			h = min(1899, h)
		l += c[i]
		h += c[i]
	if h == inf:
		return 'Infinity'
	if l > h:
		return 'Impossible'
	return h
n = int(input())
(c, d) = ([], [])
for i in range(n):
	(ci, di) = [int(item) for item in input().split()]
	c.append(ci)
	d.append(di)
print(solve(c, d))


n = int(input())
ratings = []
divs = []
for i in range(n):
	(a, b) = map(int, input().split())
	ratings.append(a)
	divs.append(b)
curmax = float('inf')
curmin = float('-inf')
if n == 1:
	if divs[0] == 1:
		print('Infinity')
	else:
		print(1899 + ratings[0])
else:
	for k in range(n - 1):
		st = divs[k]
		fin = divs[k + 1]
		change = ratings[k]
		if st == 1 and fin == 2:
			if change >= 0:
				print('Impossible')
				break
			curmax = min(curmax + change, 1899)
			curmin = max(curmin + change, 1900 + change)
		elif st == 2 and fin == 2:
			curmax = min(curmax + change, 1899, 1899 + change)
			curmin += change
		elif st == 1 and fin == 1:
			curmin = max(curmin + change, 1900, 1900 + change)
			curmax += change
		elif st == 2 and fin == 1:
			if change <= 0:
				print('Impossible')
				break
			curmax = min(curmax + change, 1899 + change)
			curmin = max(curmin + change, 1900)
	else:
		if curmax == float('inf'):
			print('Infinity')
		elif curmin > curmax:
			print('Impossible')
		else:
			print(curmax + ratings[-1])


import pdb

def A1B2(LIST):
	flag = False
	for (a, b) in LIST:
		if b == 1:
			flag = True
		if flag and b == 2:
			return False
	return True

def A2B2(LIST):
	(a, b) = LIST[0]
	for i in range(1, len(LIST)):
		(c, d) = LIST[i]
		if b == 2 and d == 1:
			return a
		(a, b) = (c, d)

def calc(N):
	curent_value = 0
	(first, second) = map(int, input().split())
	cont = list()
	cont.append((0, second))
	old_change = first
	current_value = 0
	last_value = first
	for _ in range(N - 1):
		(change, division) = map(int, input().split())
		current_value += old_change
		cont.append((current_value, division))
		old_change = change
		last_value = current_value + change
	sort_cont = sorted(cont)
	(a, b) = sort_cont[-1]
	if all((b == 1 for (a, b) in sort_cont)):
		return 'Infinity'
	if all((b == 2 for (a, b) in sort_cont)):
		(a, b) = sort_cont[-1]
		return 1899 - a + last_value
	if not A1B2(sort_cont):
		return 'Impossible'
	if len(sort_cont) == 0:
		return 1899 - first
	else:
		return 1899 - A2B2(sort_cont) + last_value
N = int(input())
print(calc(N))


import sys

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

def iinput():
	return int(input())

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

def listinput():
	return list(map(int, input().split()))
rate = 0
a = 10 ** 9
b = -a
for _ in range(iinput()):
	(r, d) = minput()
	if d == 1:
		b = max(b, 1900 - rate)
	else:
		a = min(a, 1899 - rate)
	rate += r
if a >= 10 ** 9:
	print('Infinity')
elif a < b:
	print('Impossible')
else:
	print(a + rate)


def main():
	(n,) = read()
	(mn, mx) = (-10 ** 18, 10 ** 18)
	for _ in range(n):
		(c, d) = read()
		if d == 1:
			mn = max(mn, 1900)
		elif d == 2:
			mx = min(mx, 1899)
		mn += c
		mx += c
	if mn > mx:
		print('Impossible')
		return
	if mx > 10 ** 17:
		print('Infinity')
		return
	print(mx)

def read(callback=int):
	return list(map(callback, input().strip().split()))

def write(value, end='\n'):
	if value is None:
		return
	try:
		value = ' '.join(map(str, value))
	except:
		pass
	print(value, end=end)
write(main())


n = int(input())
up = -10 ** 9
down = -up
for i in range(n):
	(c, d) = map(int, input().split())
	if d == 1:
		up = max(1900, up)
	else:
		down = min(1899, down)
	up += c
	down += c
if down < up:
	print('Impossible')
elif down >= 10 ** 8:
	print('Infinity')
else:
	print(down)


n = int(input())
score = 0
div2_max = -100000000
only_div1 = 1
div = 0
change = 0
contest = [(0, 0)] * (n + 5)
for i in range(1, n + 1):
	(c, d) = map(int, input().split())
	only_div1 &= d == 1
	if div == 1 and d == 2 and (change >= 0):
		print('Impossible')
		exit()
	if div == 2 and d == 1 and (change <= 0):
		print('Impossible')
		exit()
	contest[i - 1] = (d, score)
	if d == 2:
		div2_max = max(div2_max, score)
	score += c
	change = c
	div = d
for i in range(n):
	if contest[i][0] == 2 and contest[i][1] > div2_max:
		print('Impossible')
		exit()
	if contest[i][0] == 1 and contest[i][1] <= div2_max:
		print('Impossible')
		exit()
if only_div1:
	print('Infinity')
else:
	print(score + (1899 - div2_max))


n = int(input())
loi = []
infinity = False
impossible = False
for i in range(n):
	loi.append(list(map(int, input().split(' '))))
if loi[0][1] == 1:
	upper_bound = 99999999999999999
	lower_bound = 1900
	last_div = 1
if loi[0][1] == 2:
	upper_bound = 1899
	lower_bound = -99999999999999999
	last_div = 2
for (c, d) in loi:
	if d == 2 and lower_bound > 1899:
		impossible = True
	if d == 1 and upper_bound < 1900:
		impossible = True
	if d == 1:
		lower_bound = max(lower_bound, 1900)
	if d == 2:
		upper_bound = min(upper_bound, 1899)
	upper_bound += c
	lower_bound += c
	if lower_bound > upper_bound:
		impossible = True
	last_div = d
if impossible:
	print('Impossible')
elif upper_bound > 10000000000000000:
	print('Infinity')
else:
	print(upper_bound)


Q = int(input())
change = 0
D1 = []
D2 = []
check1 = 0
check2 = 0
(change, start) = list(map(int, input().strip().split(' ')))
pred = start
for i in range(1, Q):
	(c, d) = list(map(int, input().strip().split(' ')))
	if i == 1:
		if d == 1:
			MIN1 = change
			D1 = [MIN1]
		else:
			MAX2 = change
			D2 = [MAX2]
		change += c
	elif d == 1:
		if len(D1) == 0:
			MIN1 = change
			D1 = [change]
			change += c
		else:
			if MIN1 > change:
				MIN1 = change
				D1 = [change]
			change += c
	elif len(D2) == 0:
		MAX2 = change
		D2 = [change]
		change += c
	else:
		if MAX2 < change:
			MAX2 = change
			D2 = [change]
		change += c
if Q == 1:
	if start == 1:
		print('Infinity')
	else:
		print(1899 + change)
elif start == 1:
	if D2 == []:
		print('Infinity')
	else:
		if D1 == []:
			change1 = 0
		else:
			change1 = min(min(D1), 0)
		change2 = max(D2)
		if max(1900, 1900 - change1) <= 1899 - change2:
			print(1899 - change2 + change)
		else:
			print('Impossible')
elif D1 == []:
	temp = change
	if D2 == []:
		temp2 = 0
	else:
		temp2 = max(max(D2), 0)
	if temp2 > 0:
		ans = 1899 - temp2 + change
		print(ans)
	else:
		ans = 1899 + change
		print(ans)
else:
	if D1 == []:
		change1 = 0
	elif D1 == 0:
		change1 = 0
	else:
		change1 = min(D1)
	if D2 == []:
		change2 = 0
	else:
		change2 = max(D2)
	if 1900 - change1 <= min(1899 - change2, 1899):
		print(min(1899 - change2, 1899) + change)
	else:
		print('Impossible')


from sys import stdin
from math import inf
from functools import reduce
from collections import defaultdict
input = stdin.readline
put = lambda : list(map(int, input().split()))
mod = int(1000000000.0 + 7)
(q,) = put()
(lower, upper) = (-inf, inf)
for _ in range(q):
	(x, d) = put()
	if d == 1:
		lower = max(lower, 1900)
	else:
		upper = min(upper, 1899)
	(lower, upper) = (lower + x, upper + x)
if upper < lower:
	print('Impossible')
elif upper == inf:
	print('Infinity')
else:
	print(upper)


n = int(input())
minr = -1000000000000000000
maxr = 1000000000000000000
for i in range(n):
	(c, div) = [int(x) for x in input().split()]
	if div == 1:
		if minr < 1900:
			minr = 1900
	elif maxr >= 1900:
		maxr = 1899
	minr += c
	maxr += c
if minr > maxr:
	print('Impossible')
elif maxr > 10000000000:
	print('Infinity')
else:
	print(maxr)


import heapq
from bisect import bisect_left, bisect_right
from collections import Counter
from itertools import accumulate
import math
R = lambda : map(int, input().split())
(n, r) = (int(input()), [-math.inf, math.inf])
for i in range(n):
	(d, l) = R()
	if l == 1:
		r[0] = int(max(r[0], 1900))
	else:
		r[1] = int(min(r[1], 1899))
	if r[0] > r[1]:
		print('Impossible')
		exit()
	(r[0], r[1]) = (r[0] + d, r[1] + d)
if r[1] < math.inf:
	print(int(r[1]))
else:
	print('Infinity')


n = int(input())
(c, d) = map(int, input().split())
min_ = 0
max_ = 0
flag = True
if d == 1:
	min_ = 1900
	max_ = float('+Inf')
else:
	min_ = float('-Inf')
	max_ = 1899
for i in range(n - 1):
	(c1, d) = map(int, input().split())
	if d == 1:
		min_ = max(min_ + c, 1900)
		max_ += c
	else:
		max_ = min(max_ + c, 1899)
		min_ += c
	if min_ > max_:
		flag = False
	c = c1
min_ += c
max_ += c
if not flag:
	print('Impossible')
elif max_ == float('+Inf'):
	print('Infinity')
else:
	print(max_)


n = int(input())
r = [0] * n
d = [0] * n
for i in range(n):
	(r[i], d[i]) = map(int, input().split())
s = 0
(a, b) = (float('infinity'), -float('infinity'))
for i in range(n):
	if d[i] == 1:
		a = min(a, s)
	else:
		b = max(b, s)
	s += r[i]
ans = 1899 - b
if ans >= float('infinity'):
	print('Infinity')
elif b >= a:
	print('Impossible')
else:
	print(ans + s)


import sys
n = int(input())
(change, m) = (0, 0)
(s, t) = (-pow(10, 8), pow(10, 8))
ar = []
(rat, div) = ([], [])
for i in range(n):
	(c, d) = map(int, input().split(' '))
	div.append(d)
	ar.append(c)
	if d == 1:
		s = max(s, 1900)
	else:
		t = min(t, 1899)
	if s > t:
		print('Impossible')
		exit()
	(s, t) = (s + c, t + c)
	if d == 2:
		rat.append(change)
	change += c
if len(rat) == 0:
	print('Infinity')
else:
	print(1899 + (change - max(rat)))


n = int(input())
events = []
for line in range(n):
	(c, d) = map(int, input().split())
	events.append((c, d))
if events[0][1] == 1:
	lb = 1900
	ub = float('inf')
else:
	lb = float('-inf')
	ub = 1899

def normalise_into(div):
	global lb, ub
	if div == 1 and lb < 1900:
		lb = 1900
	if div == 1 and ub < 1900:
		return False
	if div == 2 and lb >= 1900:
		return False
	if div == 2 and ub >= 1900:
		ub = 1899
	return True
for (a, b) in zip(events, events[1:]):
	lb += a[0]
	ub += a[0]
	if not normalise_into(b[1]):
		print('Impossible')
		break
else:
	lb += events[-1][0]
	ub += events[-1][0]
	print('Infinity' if ub == float('inf') else ub)


n = int(input())
con = []
for i in range(n):
	(r, d) = map(int, input().split())
	con.append((r, d))
if all((c[1] == 1 for c in con)):
	print('Infinity')
	exit()
tot = 0
if con[0][1] == 1:
	(s, f) = (1900, 10 ** 19)
else:
	(s, f) = (-10 ** 19, 1899)
for i in range(n - 1):
	tot += con[i][0]
	aft = con[i + 1][1]
	if aft == 2:
		f = min(f, 1899 - tot)
	else:
		s = max(s, 1900 - tot)
if s > f:
	print('Impossible')
else:
	print(f + tot + con[-1][0])


(s, t) = (-10 ** 8, 10 ** 8)
for i in range(int(input())):
	(c, d) = map(int, input().split())
	if d == 1:
		s = max(s, 1900)
	else:
		t = min(t, 1899)
	if s > t:
		print('Impossible')
		exit()
	(s, t) = (s + c, t + c)
print('Infinity' if t > 5 * 10 ** 7 else t)


n = int(input())
INF = 10 ** 18
l = -INF
r = INF
s = 0
for _ in range(n):
	(c, d) = map(int, input().split())
	if d == 1 and l + s < 1900:
		l = 1900 - s
	if d == 2 and r + s >= 1900:
		r = 1899 - s
	s += c
	if l < -INF:
		l = -INF
	if r > INF:
		r = INF
if l > r:
	print('Impossible')
elif r > 10 ** 15:
	print('Infinity')
else:
	print(r + s)


import os
import sys
from io import BytesIO, IOBase
import math
import itertools
import bisect
import heapq

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.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')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	for i in range(2, n + 1):
		if primes[i]:
			for j in range(i + i, n + 1, i):
				primes[j] = False
	p = []
	for i in range(0, n + 1):
		if primes[i]:
			p.append(i)
	return p

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac
n = int(input())
(div1, div2) = (-10 ** 18, 10 ** 18)
for i in range(0, n):
	(c, d) = map(int, input().split())
	if d == 2:
		div2 = min(div2, 1899)
	else:
		div1 = max(div1, 1900)
	div1 += c
	div2 += c
if div2 >= div1:
	if div2 > 10 ** 10:
		print('Infinity')
	else:
		print(div2)
else:
	print('Impossible')


n = int(input())
up = 999999999999
down = -99999999999
sum = 0
for i in range(n):
	(a, d) = map(int, input().split(' '))
	if d == 1:
		down = max(down, 1900 - sum)
	else:
		up = min(up, 1899 - sum)
	sum += a
if up < down:
	print('Impossible')
elif up == 999999999999:
	print('Infinity')
else:
	print(up + sum)


n = int(input())
(c, d) = ([], [])
for i in range(n):
	(ci, di) = map(int, input().split())
	(c.append(ci), d.append(di))
s = [0] * (n + 1)
(geq, leq) = (0, 0)
for i in reversed(range(n)):
	s[i] = s[i + 1] + c[i]
	if d[i] == 1:
		if geq == 0:
			g = s[i] + 1900
		else:
			g = max(g, s[i] + 1900)
		geq += 1
	elif d[i] == 2:
		if leq == 0:
			l = s[i] + 1899
		else:
			l = min(s[i] + 1899, l)
		leq += 1
if leq == 0:
	print('Infinity')
elif geq == 0 or g <= l:
	print(l)
else:
	print('Impossible')


MAX = 999999999

def do():
	n = int(input())
	mx = MAX
	mn = -MAX
	(change, thisDiv) = list(map(int, input().split()))
	ratingChange = [0, change]
	divChange = [0, thisDiv]
	for i in range(n - 1):
		(change, thisDiv) = list(map(int, input().split()))
		ratingChange.append(ratingChange[-1] + change)
		divChange.append(thisDiv)
	for i in range(n):
		if divChange[i + 1] == 1:
			mn = max(1900 - ratingChange[i], mn)
		else:
			mx = min(1899 - ratingChange[i], mx)
	if mn > mx:
		return 'Impossible'
	elif mx == MAX:
		return 'Infinity'
	else:
		return str(mx + ratingChange[-1])
print(do())


n = int(input())
INF = 2 ** 60
(lo, hi) = (-INF, INF)
for i in range(n):
	(x, y) = (int(_) for _ in input().split())
	if y == 2:
		hi = min(hi, 1899)
	else:
		lo = max(lo, 1900)
	hi += x
	lo += x
if lo > hi:
	print('Impossible')
elif hi > 2 ** 31:
	print('Infinity')
else:
	print(hi)


n = int(input())
I = lambda : map(int, input().split())
t1 = 0
t2 = 0
j = 0
for _ in range(n):
	(x, y) = I()
	if y == 1:
		if t1 == 0:
			mi = j
		else:
			mi = min(mi, j)
		t1 += 1
	else:
		if t2 == 0:
			ma = j
		else:
			ma = max(ma, j)
		t2 += 1
	j += x
if t1 == n:
	exit(print('Infinity'))
elif t2 == n:
	exit(print(1899 - max(0, ma) + j))
eff1 = 1899 - ma
eff2 = 1900 - mi
if eff1 > eff2:
	exit(print(max(eff1, eff2) + j))
if eff1 == eff2:
	exit(print(eff1 + j))
else:
	exit(print('Impossible'))


import sys

def change_rating(div, change):
	if div == 1:
		ranged[0] = max(ranged[0], 1900)
	else:
		ranged[1] = min(ranged[1], 1899)
	if ranged[0] > ranged[1]:
		return False
	ranged[0] += change
	ranged[1] += change
	return True

def get_max_cur(start):
	t = start
	m = start
	for change in reversed(changes):
		m = max(m, start - change)
		start -= change
	if m >= inf:
		return m
	return t
n = int(input())
inf = sys.maxsize * 2000
ranged = [-inf, inf]
changes = []
for _ in range(n):
	(chnage, div) = list(map(int, input().split()))
	if not change_rating(div, chnage):
		print('Impossible')
		return
	changes.append(chnage)
max_r = get_max_cur(ranged[1])
if max_r >= inf:
	print('Infinity')
else:
	print(max_r)


read = lambda : map(int, input().split())
n = int(input())
inf = 10 ** 9
cur = inf
a = [tuple(read()) for i in range(n)]
dif = 0

def fail():
	print('Impossible')
	exit()
flag = True
Min = -inf
for i in range(n):
	(c, d) = a[i]
	if d == 2:
		flag = False
	if d == 2 and cur >= 1900:
		cur = 1899
		if cur < Min:
			fail()
	if d == 1 and cur < 1900:
		fail()
	if d == 1:
		Min = max(Min, 1900)
	cur += c
	Min += c
if flag:
	print('Infinity')
	exit()
ans = cur
print(ans)


n = int(input())
C = []
D = []
for i in range(n):
	(c, d) = list(map(int, input().strip().split()))
	C.append(c)
	D.append(d)
flag = True
if max(D) == min(D) and max(D) == 1:
	print('Infinity')
else:
	if max(D) == min(D) and max(D) == 2:
		flag = False
	a = []
	b = []
	if D[0] == 1:
		a.append(0)
	else:
		b.append(0)
	currsum = 0
	prefix_sums = [0]
	for i in range(1, n):
		currsum += C[i - 1]
		prefix_sums.append(currsum)
		if D[i] == 1:
			a.append(currsum)
		else:
			b.append(currsum)
	if flag:
		lowest_red_point = min(a)
	highest_blue_point = max(b)
	if flag and lowest_red_point <= highest_blue_point:
		print('Impossible')
	else:
		for i in range(n):
			if prefix_sums[i] == highest_blue_point:
				bp = i
		print(1899 + sum(C[bp:]))


from math import sin

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

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

def pt(x):
	print(x)

def ip():
	return input()

def it():
	return int(input())

def sl(x):
	return [t for t in x]

def spl(x):
	return x.split()

def aj(liste, item):
	liste.append(item)

def bin(x):
	return '{0:b}'.format(x)

def listring(l):
	return ' '.join([str(x) for x in l])

def ptlist(l):
	print(' '.join([str(x) for x in l]))
n = it()
c = []
d = []
for _ in range(n):
	(a, b) = mp()
	c.append(a)
	d.append(b)
s = [-1 for i in range(n)]
s[0] = 0
for i in range(1, n):
	s[i] = s[i - 1] + c[i - 1]
w = s[-1] + c[n - 1]
r = list(zip(s, d))
r.sort(reverse=True)
k = 0
while k < n and r[k][1] == 1:
	k += 1
if k < n and any((r[j][1] == 1 for j in range(k, n))):
	pt('Impossible')
elif k == n:
	pt('Infinity')
elif k == 0:
	m = r[0][0]
	pt(1899 - m + w)
else:
	q = r[k][0]
	pt(1899 - q + w)


n = int(input())
up = 0
wasup = 0
down = 0
wasdown = 0
for i in range(n):
	(c, d) = [int(i) for i in input().split()]
	if d == 1:
		if not wasdown:
			down = 1900
			wasdown = 1
		down = max(down, 1900)
		down += c
		if wasup:
			up += c
	if d == 2:
		if not wasup:
			up = 1899
			wasup = 1
		up = min(up, 1899)
		up += c
		if wasdown:
			down += c
	if wasup and wasdown:
		if up < down:
			print('Impossible')
			break
else:
	if wasup:
		print(up)
	else:
		print('Infinity')


from sys import *
from decimal import *
from math import *
n = int(stdin.readline())
(u, v) = (int(z) for z in stdin.readline().split())
if v == 2:
	cmaxr = 1899 + u
	cminr = -10 ** 12
else:
	cmaxr = 10 ** 12
	cminr = 1900 + u
for i in range(n - 1):
	(u, v) = (int(z) for z in stdin.readline().split())
	if v == 2 and cminr >= 1900 or (v == 1 and cmaxr <= 1899):
		print('Impossible')
		exit(0)
	if v == 2:
		cmaxr = min(1899, cmaxr)
	else:
		cminr = max(1900, cminr)
	cmaxr += u
	cminr += u
if cmaxr >= 10 ** 11:
	print('Infinity')
else:
	print(cmaxr)


def ri():
	return map(int, input().split())
n = int(input())
maxr = 100 * 200000 + 10 ** 9
minr = -maxr
INF = maxr
if n == 1:
	(c, d) = ri()
	if d == 1:
		print('Infinity')
	else:
		print(1899 + c)
	exit()
csum = 0
r = 0
(c, d) = ri()
cprev = c
dprev = d
if d == 1:
	r = maxr
	minr = 1900
else:
	r = 1899
	maxr = 1899
for i in range(1, n):
	(c, d) = ri()
	csum += cprev
	r += cprev
	if dprev == 1 and d == 1:
		if cprev >= 0:
			pass
		elif r < 1900:
			print('Impossible')
			exit()
		else:
			minr = max(minr, 1900 - csum)
			if maxr < minr:
				print('Impossible')
				exit()
	if dprev == 1 and d == 2:
		if cprev >= 0:
			print('Impossible')
			exit()
		elif r >= 1900:
			maxr = 1899 - csum
			if maxr < minr:
				print('Impossible')
				exit()
			r = 1899
		else:
			maxr = min(maxr, 1899 - csum)
			if maxr < minr:
				print('Impossible')
				exit()
	if dprev == 2 and d == 1:
		if cprev <= 0:
			print('Impossible')
			exit()
		elif r < 1900:
			print('Impossible')
			exit()
		else:
			minr = max(minr, 1900 - csum)
			if maxr < minr:
				print('Impossible')
				exit()
	if dprev == 2 and d == 2:
		if cprev > 0:
			if r >= 1900:
				maxr = 1899 - csum
				r = 1899
				if maxr < minr:
					print('Impossible')
					exit()
			else:
				maxr = min(maxr, 1899 - csum)
				if maxr < minr:
					print('Impossible')
					exit()
	cprev = c
	dprev = d
if maxr == INF:
	print('Infinity')
else:
	print(r + c)