def guess(n, m, sc):
    ans = [-1] * n
    for s, c in sc:
        if ans[s-1] != -1 and ans[s-1] != c:
            # 矛盾
            return -1
        ans[s-1] = c
    ans = [max(a, 0) for a in ans]
    if ans[0] == 0:
        return -1
    return ''.join(map(str, ans))

def main():
    n, m = map(int, input().split())
    sc = [tuple(map(int, input().split())) for _ in range(m)]
    print(guess(n, m, sc))

main()
