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: interview

Starter code:

Solutions:
"""
Codeforces Good Bye 2016 Contest Problem C

Author  : chaotic_iak
Language: Python 3.5.2
"""

################################################### SOLUTION

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)

#################################################### HELPERS

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


#!/usr/bin/env python3

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] = list(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()


num_contests = int(input())

rating = 0

upper_bound = None
lower_bound = None

for contest_num in range(num_contests):
    ci, di = list(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)


import sys
import math

def solve():
    n = int(input())
    l, r = -float('inf'), float('inf')
    for line in sys.stdin:
        c, d = list(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())
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)


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)
        #print(mn, mx)
    if mn > mx: return "Impossible"
    else:
        if mx == MAX: return "Infinity"
        else: return str(mx + ratingChange[-1])

print(do())


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
    else:
        if maxr >= 1900:
            maxr = 1899
    minr += c
    maxr += c

if minr > maxr:
    print("Impossible")
elif maxr > 10000000000:
    print("Infinity")
else:
    print(maxr)


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
    else:
        if 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')

from math import inf

def main():
    n = int(input())
    l = -inf
    r = inf
    for i in range(n):
        c, d = list(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()


q=int(input())
q-=1
a,s=list(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=list(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)


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')
else:
    if MAX > INF:
        print('Infinity')
    else:
        print(MAX)


#!/usr/bin/env python3

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()))
        # print("was div{}, took {} rating".format(d, c))
        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
        # print("min: {}, max: {}".format(min_rating, max_rating))

    if max_rating is None:
        return "Infinity"
    return max_rating

def __starting_point():
    print(solve())

__starting_point()

'''
Created on 30 dec. 2016

@author: Moldovan
'''

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:#div 2
        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)
            


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 collections import defaultdict
import sys, os, math

def __starting_point():
    #n, m = list(map(int, input().split()))
    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)
__starting_point()

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
        else:
            if (y == None):
                y = 1900
            else:
                y = max(y, 1900)
    else:
        if (y != None) and (y > 1899):
            proof = False
        else:
            if (x == None):
                x = 1899
            else:
                x = min(x, 1899)
if (proof):
    if (x == None):
        print("Infinity")
    else:
        print(x + c)
else:
    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)



# Author: Maharshi Gor
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)
    # print(diff, d, l, u)
    diff += r
    if u < l:
        e = True
        break


if e or l > u:
    print("Impossible")
elif u == inf:
    print("Infinity")
else:
    print(u + diff)


n = int(input())
c, d = list(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 = list(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())

# Init

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


# Loop

for (c,d) in loi:
    if d == 2 and lower_bound > 1899:
        impossible = True
    if d == 1 and upper_bound < 1900:
        impossible = True
    # print("-----")
    # print(lower_bound, upper_bound)

    if d == 1:
        lower_bound = max(lower_bound, 1900)
    if d == 2:
        upper_bound = min(upper_bound, 1899)
    # print(lower_bound, upper_bound)

    # if last_div == d:
    upper_bound += c
    lower_bound += c

    # if last_div ==1 and d == 2:
    #     upper_bound = min(1899, upper_bound+c)
    #     lower_bound = lower_bound+c
    # if last_div ==2 and d == 1:
    #     upper_bound = upper_bound + c
    #     lower_bound = max(1900,lower_bound+c)

    if lower_bound > upper_bound:
        impossible = True

    # print(lower_bound, upper_bound)
    last_div = d


if impossible:
    print("Impossible")
elif upper_bound>10000000000000000:
    print("Infinity")
else:
    print(upper_bound)

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