string = input()
n = int(string.split()[0])
m = int(string.split()[1])
s = [0]*m
c = [0]*m
ans = [0]*n
flag = True

for i in range(m):
    string = input()
    s[i] = int(string.split()[0])
    c[i] = int(string.split()[1])

if len(set(s)) > n:
    flag = False
for i in range(m):
    for j in range(i, m):
        if s[j] == s[i] and c[j] != c[i]:
            flag = False

for i in range(m):
    ans[s[i] - 1] = c[i]

if ans[0] == 0:
    flag = False

if flag:
    print(''.join([str(x) for x in ans]))
else:
    print("-1")
