N, M = map(int, input().split())
ans_l = [0 for i in range(N)]
ans = ""
bool_list = [False for i in range(N)]
flag = 0
S = []
C = []

for m in range(M):
    s, c = map(int, input().split())
    if (bool_list[s-1] == True) & (ans_l[s-1] != c):
        ans = "-1"
        flag = 1
        break
    else:
        ans_l[s-1] = c
        S.append(s)
        C.append(c)
        

if flag == 0:
    if (bool_list[0]==False) & (N==3):
        ans_l[0]=1
    elif (bool_list[0]==False) & (N==2):
        ans_l[0]=1
if flag == 0:
    if (N==3) & (ans_l[0] == 0):
        ans = "-1"
        flag = 1
    elif (N==2) & (ans_l[0] == 0):
        ans = "-1"
        flag =1
if flag == 0:
    for i in ans_l:
        ans += str(i)

ans = int(ans)

if len(str(ans)) != N:
    ans
print(ans)