#!/usr/bin/env python3
(n, _), *m = [[*map(int, i.split())] for i in open(0)]

a = [1]+[0] * ~-n

for s, c in m:
    if s==1 and a[s-1] in (1,c):
        a[s-1] = c
    elif a[s - 1] in (0, c):
        a[s - 1] = c
    else:
        print(-1)
        exit()

a = int("".join([*map(str, a)]))
if a < 10**(n-1):
    print(-1)
else:
    print(a)
