n,m = list(map(int,input().split()))
a = []
res_list = []
res = ""
flag = True

for i in range(m):
    a.append(list(map(int,input().split())))

for i in range(n):
    res_list.append("0")

for i in range(m):
    res_list[a[i][0]-1] = str(a[i][1])
    if a[i][0] == 1 and a[i][1] == 0:
        flag = False
        break
    for j in range(m):
        if a[i][0] == a[j][0] and a[i][1] != a[j][1]:
            flag = False
            break

if n == 1 and int(res_list[0]) == 0:
    flag = False

if res_list[0] == "0":
    res_list[0] = "1"

for i in res_list:
    res += i

if flag == False:
    print(-1)
else:
    print(res)

