N, M = tuple(map(int, input().split(' ')))
s = list()
c = list()
dic = {}
for m in range(M):
    ts , tc = tuple(map(int, input().split(' ')))
    s.append(ts)
    c.append(tc)

is_cannnot = False
for i in range(len(s)):
    if not s[i] in dic.keys():
        dic[s[i]] = c[i]
    elif dic[s[i]] == c[i]:
        pass
    else:
        is_cannnot = True
        break

if 1 in s and dic[1] == 0:
    is_cannnot = True

ans = [0 for i in range(N)]
if is_cannnot:
    print(-1)
else:
    for k in dic.keys():
        ans[k - 1] = dic[k]
    if ans[0] == 0:
        ans[0] = 1
    print(''.join(map(str, ans)))
    