#!python3.4
# -*- coding: utf-8 -*-
# abc157/abc157_c
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M = i2nn()
    res = ['1'] + ['0'] * max(N, M)
    s_max = 0
    s_min = M
    s_dict = {}
    for i in range(M):
        s, c = i2nn()
        s -= 1
        if (s in s_dict and s_dict[s] != c):
            print(-1)
            return
        s_dict[s] = c
        s_max = max(s, s_max)
        s_min = min(s, s_min)
        res[s] = str(c)
    if (N > 0 and res[0] == '0'):
        print(-1)
        return
    if (N < s_max+1):
        print(-1)
        return
    res_str = ''.join(res[:N])
    print(res_str)
    return

main()
