n,m = map(int, input().split())

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

if (not valid):
    print(-1)
else:
    num = list(map(lambda x: 0 if x==-1 else x, theNumber))
    if (num[0] == 0):
        num[0] = 1
    print(''.join(map(str, num)))
    
