#coding:utf-8
import sys,os
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N, M = LMIIS()
    SC = XLMIIS(M)
    ans = [-1] * N
    for s,c in SC:
        if ans[s-1] != -1 and ans[s-1] != c:
            print(-1)
            return
        else:
            ans[s-1] = c

    if ans[0] == 0:
        print(-1)
        return

    if ans[0] == -1:
        ans[N-1] = 1

    intans = 0
    for a in ans:
        intans *= 10
        if a != -1:
            intans += a
    print(intans)

    

if __name__ == '__main__':
    main()