#!/usr/bin/env python3
n,m = map(int,input().split())
s = [0]*n
c = [0]*n
digit = [-1]*3
for i in range(m):
    s[i],c[i] =map(int,input().split())
    if digit[s[i]-1] == -1: digit[s[i]-1] = c[i]
    elif digit[s[i]-1] != c[i]: 
        print(-1)
        exit()
if digit[0] == 0:
    print(-1)
    exit()
for i in range(3):
    if digit[i] == -1:
        print(max(1-i,0),end="")
    else: print(digit[i],end="")
        