import math
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))
mod = 10**9 + 7 
sys.setrecursionlimit(1000010)

N,M = nm()
digits = [-1] * N
# print(N,M)
for i in range(M):
    s,c = nm()
    # print(s,c)
    ii = s -1 
    # print("A",ii,c)
    if digits[ii] == -1:
        digits[ii] = c
    elif digits[ii] != c:
        print(-1)
        exit(0)

# print(digits)
if N == 1:
    if digits[0] == -1:
        print(0)
    else:
        print(digits[0])
    exit(0)

if digits[0] == -1:
    digits[0] = 1
elif digits[0] == 0:
    print(-1)
    exit(0)

for i in range(1,M):
    if digits[i] == -1:
        digits[i] = 0

xx = "".join(list(map(str,digits)))
print(xx)
