import collections as c
import sys
input = sys.stdin.readline
ip = lambda : map(int, input().split())
mod = 10**9+7
# ##############
N,M = ip()
S = {}
for i in range(M):
    s,c = ip()
    if s not in S:
        S[s] = c
    elif S.get(s,10) == c:
        continue
    else:
        print(-1)
        exit()
ans = 0
for i in range(1,1+N):
    if i==1:
        ans += S.get(i,1)*10**(N-i)
    else:ans += S.get(i,0)*10**(N-i)
if ans>=10**(N-1):
    print(ans)
else:print(-1)