# -*- coding: utf-8 -*-
"""
Created on Sun Mar  1 20:52:55 2020

@author: H_Hoshigi
"""

N, M = map(int, input().split())

s_c_dict = {}
for i in range(1, N+1):
    s_c_dict[i] = -1

for i in range(M):
    s_c_list = list(map(int, input().split()))
    if s_c_dict[s_c_list[0]] == -1:
        s_c_dict[s_c_list[0]] = s_c_list[1]
    elif s_c_dict[s_c_list[0]] != s_c_list[1]:
        s_c_dict[s_c_list[0]] = -2
    else:
        s_c_dict[s_c_list[0]] = s_c_list[1]

answer = ""

if s_c_dict[1] == -2 or s_c_dict[1] == 0:
    answer = "-1"
elif s_c_dict[1] == -1:
    answer += "1"
else:
    answer += str(s_c_dict[1])
if answer != "-1":
    for i in range(2, N+1):
        if s_c_dict[i] == -2:
            answer = "-1"
            break
        elif s_c_dict[i] == -1:
            answer += "0"
        else:
            answer += str(s_c_dict[i])

print(answer)

