import sys

N, M = map(int, input().split())
sclist = []
for i in range(M):
    s, c = map(int, input().split())
    sclist.append([s, c])
num = [None] * N

for i in sclist:
    if num[i[0] - 1] is not None:
        if num[i[0] - 1] != i[1]:
            print('-1')
            sys.exit()
    num[i[0] - 1] = i[1]

for i, n in enumerate(num):
    if n is None:
        num[i] = 0

if N >= 2:
    if num[0] == 0:
       num[0] == 1

for i in num:
    print(i, end='')
