n, m = map(int, input().split())
s, c = [], []
for i in range(m):
    a, b = map(int, input().split())
    s.append(a), c.append(b)

dicts = {}

ans = [0 for i in range(n)]
b = 0

for i in range(m):
    if s[i] not in dicts:
        dicts[s[i]] = c[i]
    elif s[i] in dicts and dicts[s[i]] != c[i]:
        print('-1')
        break


    if i == m - 1:
        for j in range(n + 1):
            if j in dicts:
                ans[j - 1] = dicts[j]
        # print(ans)
        for j in range(n):
            b += ans[n - j - 1] * (10 ** j)
        if b >= 10 ** (n - 1) and b <= (10 ** n) - 1:
            print(''.join(map(str, ans)))
        else:
            print('-1')
