# -*- coding: utf-8 -*-

## Library

import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input

# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))

N,M = map(int,input().split()) 
S = [list(map(int,input().split())) for i in range(M)]

if M == 0:
    print(-1)
    sys.exit() 


ans = []
for i in range(N):
    ans.append(-1)

for i in range(M):
    if ans[S[i][0]-1] == -1:
        ans[S[i][0]-1] = S[i][1]
    else:
        if ans[S[i][0]-1] != S[i][1]:
            print(-1)
            sys.exit()

if N==3:
    if ans[0] == 0:
        print(-1)
        sys.exit()
    elif ans[0] == -1 and ans[1] ==0:    
        print(-1)
        sys.exit()   
elif N==2:
    if ans[0]==0:
        print(-1)
        sys.exit() 

for i in range(N):
    if ans[i] == -1:
        print(0, end='')
    else:
        print(ans[i],end='')
print()