import sys

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

str_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()

 #   if n < s:
 #       print(-1)
 #       sys.exit()

    dict[s] = c 



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

try:
    ans = int(str_ans)
except ValueError:
    print(-1)
    sys.exit()

if str_ans != str(ans):
    print(-1)
    sys.exit()

print(ans)