import sys

N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]

ll = [[] for _ in range(N)]

for s, c in SC:
    ll[s - 1].append(c)
    if s == 1 and c == 0:
        print('-1')
        sys.exit()

ans = []
for i in range(N):
    if len(ll[i]) > 1:
        k = list(set(ll[i]))
        if len(k) > 1:
            print('-1')
            sys.exit()
        else:
            ans.append(k[0])

    elif len(ll[i]) == 0:
        ans.append(0)
    else:
        ans.append(ll[i][0])

if ans[0] == 0:
    ans[0] = 1

f = 0
for i in range(N):
    f += ans[i] * 10**(N - 1 - i)

print(f)
