def main():
    n, m = map(int, input().split(" "))
    num = [-1] * 9
    max_col = 0
    for i in range(m):
        s, c = map(int, input().split(" "))
        if num[s - 1] != -1 and num[s - 1] != c:
            print("-1")
            return
        num[s - 1] = c
        if s > max_col:
            max_col = s
    start = False
    ans = ""
    for i, v in enumerate(num, 1):
        if i > max_col:
            break
        if not start and v == -1:
            continue
        elif not start and v == 0:
            continue
        else:
            start = True
            if v == -1:
                ans += "0"
            else:
                ans += str(v)
    if ans == "":
        ans = "-1"
    print(ans)


if __name__ == '__main__':
    main()
