#nは桁数　each_placeには[位,位の数]のリスト

n,m = map(int,input().split())
each_place = [[int(i) for i in input().split()] for _ in range(m)]

def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

each_place = get_unique_list(each_place)
each_place.sort()

a = True

if n >= 2 and [1,0] in each_place:
    a = False

for x in range(len(each_place)-1):
  if each_place[x][0] == each_place[x+1][0]:
    a = False
    break
if a:
    ans = 0
    for y in range(len(each_place)):
        ans += 10 ** (n-each_place[y][0]) * each_place[y][1]
    print(ans)
else:
    print(-1)
