[N, M] = [int(i) for i in input().split()]

SC = []
for i in range(M):
    [s, c] = [int(i) for i in input().split()]
    SC.append([s, c])

dic = {}
for i in range(M):
    if SC[i][0] in dic:
        if dic[SC[i][0]] != SC[i][1]:
            dic[SC[i][0]] = 'x'
        break
    else:
        dic[SC[i][0]] = SC[i][1]
U = []
if N == 1:
    U = [dic[0][1]]
else:
    for u in range(1, N+1):
        if u in dic:
            if u == 1:
                if dic[u] == 0:
                    U.append('x')
                else:
                    U.append(str(dic[u]))
            else:
                U.append(str(dic[u]))
        else:
            if u == 1:
                U.append('x')
            else:
                U.append('0')


if U.count('x') != 0:
    print(-1)
else:
    print(''.join(U))