#!/usr/bin/env python3
import sys

def s_bannme(i,s):
    ans = [d for d in str(i)]
    if len(ans)>s:
        return int(ans[s])


def solve(N: int, M: int, S: "List[int]", C: "List[int]"):
    
    
    for i in range(1000):
        exist = True
        for s, c in zip(S, C):
            digits = len(str(i))
            cons = s_bannme(i,s-1)
            if digits == N and cons == c:
                pass
            else:
                exist = False

        if exist:
            print(i)
            return
                
    print(-1)



# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    s = [int()] * (M)  # type: "List[int]"
    c = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        s[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, M, s, c)

if __name__ == '__main__':
    main()
