N, M = map(int, input().split())
s_list = []
c_list = []
for i in range(M):
    s, c = map(int, input().split())
    s_list.append(s-1)
    c_list.append(c)
l = [-1] * N
isNG = False
for i in range(M):
    if s_list[i] == 0 and c_list[i] == 0:
        isNG = True
        break
    if l[s_list[i]] == -1:
        l[s_list[i]] = c_list[i]
    else:
        if l[s_list[i]] != c_list[i]:
            isNG = True
            break
if l[0] == -1:
    isNG =True
if isNG:
    print(-1)
else:
    for i in range(N):
        if l[i] == -1:
            l[i] = 0
        print(l[i], end="")
