def main():
    n, m = map(int, input().split())
    sss = []
    ccc = []
    for _ in range(m):
        s, c = map(int, input().split())
        temp_dubs = []
        if s in sss:
            temp_dubs = [i for i, x in enumerate(sss) if x == s]
        for td in temp_dubs:
            if ccc[td] != c:
                print(-1)
                return
        sss.append(s)
        ccc.append(c)

    for i in range(10 ** (n-1), 10 ** (n+1)):
        str_i_list = list(str(i))
        break_flag = False
        for j in range(m):
            idx = sss[j] - 1
            str_i_temp = int(str_i_list[idx])
            if str_i_temp != ccc[j]:
                break_flag = True
                break
        if break_flag:
            continue
        else:
            print(i)
            return

    print(-1)


if __name__ == '__main__':
    main()
