#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, M = map(int, input().split())
    num = [0]*N
    flag = [False]*N

    for m in range(M):
        s, c = map(int, input().split())

        if s == 1 and c == 0:
            if N == 1:
                print(0)
                exit()
            else:
                print(-1)
                exit()

        if flag[s-1]:
            if num[s-1] != c:
                print(-1)
                exit()
            else:
                num[s-1] = c
                flag[s-1] = True
        else:
            num[s-1] = c
            flag[s-1] = True
    
    print(''.join(map(str, num)))


if __name__ == '__main__':
    main()