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

exist = True

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

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] != -1 and x[0] != c:
                    exist = False
                else:
                    x[0] = c
        else:
            if x[s-1] != -1 and x[s-1] != c:
                exist = False
            else:
                x[s-1] = c

    if x[0] == -1:
        exist = False
    if exist:
        x = [0 if j == -1 else j for j in x]
        x = "".join(map(str,x))
            
if exist:
    print(x)
else:
    print('-1')
