def calc():
    mp = {}
    n, m = map(int, input().split())
    for i in range(0, m):
        s, c = map(int, input().split())
        if s in mp and mp[s] != c:
            return -1
        else:
            mp[s] = c
    res = 0
    if n == 1:
        res = mp[1] if 1 in mp else 0
    else:
        for j in range(1, n + 1):
            if j == n:
                x = mp[j] if j in mp else 1
            else:
                x = mp[j] if j in mp else 0
            res += x * (10 ^ ((n - j + 1) - 1))
    if len(str(res)) != n:
        return -1
    return res


print(calc())
