def main():
    n, m = map(int, input().split())
    digit = {}
    for i in range(m):
        s, c = map(int, input().split())
        if digit.get(s) is not None and digit.get(s) != c:
            print(-1)
            return
        digit[s] = c
    ans = ''
    for i in range(1, n+1):
        ans += str(digit.get(i, '1'))

    if ans == str(int(ans)):
        print(ans)
    else:
        print(-1)


if __name__ == '__main__':
    main()
