n, m = map(int, input().split())
x = [0] * n

exist = True

if n == 1:
    sc_list = []
    for i in range(m):
        sc_list.append(list(map(int, input().split())))
    for i in range(m-1):
        if sc_list[i][1] != sc_list[i+1][1]:
            exist = False
    if exist:
        x = [sc_list[0][1]]

elif n >= 2:
    for i in range(m):
        s, c = map(int, input().split())
        if s == 1:
            if c == 0:
                exist = False
            else:
                if x[0] != 0 and x[0] != c:
                    exist = False
                else:
                    x[0] = c
        else:
            if x[s-1] != 0 and x[s-1] != c:
                exist = False
            else:
                x[s-1] = c

if n >= 2 and x[0] == 0:
    exist = False
            
if exist:
    print("".join(map(str,x)))
else:
    print(-1)
