N, M = map(int, input().split())
s_c = []
for _ in range(M):
    s_c.append(list(map(int, input().split())))
    
    
flag = False
num = [-1 for i in range(N)]
for s,c in s_c:
    if num[s-1] == -1: # 初めて出て来る. 
        num[s-1] = c
    elif not num[s-1] == c: #初めてではなさそう. そして予約されたcではなさそう. 
        flag = True

# print(num)
ans = 0
if flag:
    print(-1)
elif num[0] == 0:
    print(-1)
else:
    for i,n in enumerate(num):
        if n == -1:
            n = 0
        else:
            ans += n*(10**(2-i))
    print(ans)
  