export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [n, m]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    if (m == 0) {
      return `${n == 1 ? 0 : -1}`;
    }
    const map = {};
    for (let i = 0; i < m; i++) {
      const [s, c]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
      if ((s == 1 && c == 0 && n != 1) || (map[s] != undefined && map[s] != c)) {
        return `${-1}`;
      }
      map[s] = c;
    }
    if (n == 1) {
      return `${map[1]}`;
    }
    let result = "";
    for (let i = 1; i <= n; i++) {
      const c = map[i];
      if (c == undefined) {
        result = result + "0";
      } else {
        result = result + c;
      }
    }
    return `${result}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));
