#!/usr/bin/env python3

N, M = map(int, input().split())

max_keta = -1
d = {}
for i in range(M):
    s, c = map(int, input().split())
    if s in d:
        if d[s] == c:
            continue
        else:
            print('ochinpo')
            print(-1)
            exit()
    else:
        d[s] = c
        if max_keta < s: max_keta = s

if max_keta != N:
    print(-1)
    exit()
else:
    for i in range(1, N+1):
        if i in d: print(d[i], end='')
        else: print(0, end='')
print()

