N, M = map(int, input().split())
ans = 0
lst = [[] for i in range(3)]
for i in range(M):
    a, b = map(int, input().split())
    if b not in lst[a-1]:
        lst[a-1].append(b)
for i in range(3):
    if len(lst[i]) > 1:
        print(-1)
        exit()
    if i == 0:
        if not lst[i]:
            ans += 100
        elif lst[i][0] == 0:
            ans += 0
        else:
            ans += lst[i][0]*100
    else:
        if not lst[i]:
            ans += 0
        elif lst[i][0] == 0:
            ans += 0
        else:
            ans += lst[i][0]*(10**(2-i))       

if (ans//(10**N)) >= 1:
    print(ans)
elif ans == 0 and N == 1:
    print(ans)
else:
    print(-1)