import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  int n, m;
  readf("%s %s\n", &n, &m);
  auto res = new int[](n);
  res[] = -1;
  foreach (i; 0..m) {
    int s, c;
    readf("%s %s\n", &s, &c);
    if (res[s-1] != -1 && res[s-1] != c) {
      writeln(-1);
      return;
    }
    res[s-1] = c;
  }
  int sum;
  foreach (i; 0..n) {
    if (res[i] == -1) {
      if (i == 0 && n != 1) {
        res[i] = 1;
      } else {
        res[i] = 0;
      }
    }
    sum += res[i] * (10 ^^ (n - i - 1));
  }

  auto l = sum.to!string.length;
  if (n == l) {
    sum.writeln;
  } else {
    writeln(-1);
  }
}
