#!/bin/bash
import sys


def _ia(): return [int(x) for x in sys.stdin.readline().strip().split()]


def main():
    n, m = _ia()
    k = {i: set() for i in range(1, n + 1)}
    for _ in range(m):
        si, ci = _ia()
        k[si].add(ci)

    ans = ""
    for i in range(1, n + 1):
        lk = len(k[i])
        if lk == 0:
            if i == 1:
                k[i].add(1)
            else:
                k[i].add(0)
        elif lk == 1:
            pass
        else:
            return "-1"
        ans += str(k[i].pop())
    return "-1" if ans.startswith("0") else ans


if __name__ == "__main__":
    print(main())
