n, m = map(int, input().split())
s = [-1] * 3
si_t = [None, 3, 2, 1]
for i in range(m):
    si, ci = map(int, input().split())
    
    # n より、大きい si は NG
    if si_t[si] > n:
        print(-1)
        exit()
    
    # 先頭桁が 0 は NG
    if si > 0 and ci == 0 and n == si_t[si]:
        print(-1)
        exit()
    
    # 同じ桁
    if s[si-1] != -1 and s[si-1] != ci:
        print(-1)
        exit()

    if s[si-1] == -1:
        s[si-1] = ci

    s[si-1] = min(s[si-1], ci)

ans = ""
for i in range(1, n+1):
    if s[-i] == -1:
        s[-i] = 0
    ans = str(s[-i]) + ans

print(ans)
