date = input().split()
N = date[0]
M = date[1]
dict = {}
sum = 0
flag = 0
for i in range(int(M)):
    date = input().split()
    s = date[0]
    c = date[1]
    if s in dict.keys():
        if dict[s] != c:
            print("-1")
            flag = 1
            break
    else:
        dict[s] = c
dict = sorted(dict.items(), key=lambda x: x[0])
for i in dict:
    if int(i[1]) == 0 and int(N) != 1:
        if int(i[0]) == 1:
            print(-1)
            flag = 1
            break
    else:
        sum += 10 ** (int(N) - int(i[0])) * int(i[1])
if flag == 0:
    str = str(sum)
    l = len(str)
    if l < int(N):
        sum += 100
    print(sum)