import sys

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

ans = ''

dict = {}

for i in range(m):
    s,c = map(int, input().split())
    if s in dict.keys():
        if c != dict.get(s, c):
            print(-1)
            sys.exit()

    dict[s] = c 

for j in range(1 , n + 1):
   ans = ans + str(dict.get(j, 0))

if ans == '0':
     print(-1)
else:
    print(ans)
