#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
n, m = map(int, input().split())
List = [list(map(int, input().split())) for _ in range(m)]
num = [0]*n
ans = -1
flag = 1

for i in range(m):
    if num[List[i][0] - 1] == 0 or num[List[i][0] - 1] == List[i][1]:
        num[List[i][0] - 1] = List[i][1]
    else:
        flag = 0
        break;

if flag == 1 and num[0] != 0:
    for j in range(n):
        print(num[j], end = "")

else:
    print(ans)
