N,M = map(int,input().split())
dic = {str(i+1):0 for i in range(N)}
check = 0
for x in range(M):
    s,c = map(int,input().split())
    if dic[str(s)] != 0 and dic[str(s)] != c:
        check = 1
    if s == 1 and c == 0:
        check = 1
    dic[str(s)] = c
if dic['1'] == 0 :
    dic['1'] = 1
ans = []
for i in dic.keys():
    ans.append(str(dic[i]))
if check == 1:
    print(-1)
else:
    print(''.join(ans))
