N, M = map(int,input().split()) # 複数の数字を変数に格納
List = [list(map(int,input().split())) for i in range(M)] # [[1,2],[3,4],[5,6]]

result = str(10**(N-1))

for i in range(M):
    n = List[i][0]
    num = str(List[i][1])
    result = result[:n-1] + num + result[n:]

for i in range(M):
    for j in range(M):
        if List[i][0] == List[j][0]:
            if List[i][1] != List[j][1]:
                result = '-1'
    
if result[0] == '0':
    print(-1)
else:
    print(int(result))