def main():
    n, m = map(int, input().split())
    l = [ (input().split()) for i in range(m)]
    l.sort(key=lambda x: x[1], reverse=True)
    res = ["0"]*n
    for s, c in l:
        res[int(s)-1] = c
    res = int("".join(res))
    if len(str(res)) == n:
        print(int(res))
    else:print("-1")
 
if __name__ == "__main__":
    main()