#include <bits/stdc++.h>
using namespace std;
int N, M;
int digit[5];
int Meq0() {
  if (N == 1)
    return 0;
  else
    return (int)pow(10, N - 1);
}
int Solve3() {
  if (digit[1] == 0) digit[1] = 1;
  return digit[1] * 100 + digit[2] * 10 + digit[3];
}
int Solve2() {
  if (digit[1] == 0) digit[1] = 1;
  return digit[1] * 10 + digit[2];
}
int Solve1() { return digit[1]; }
void Solve() {
  int ans;
  if (M == 0) {
    ans = Meq0();
  } else {
    switch (N) {
      case 3:
        ans = Solve3();
        break;
      case 2:
        ans = Solve2();
        break;
      case 1:
        ans = Solve1();
        break;
    }
  }
  cout << ans << endl;
}
void Init() {
  bool set[5];
  for (int i = 0; i < (5); ++i) {
    digit[i] = 0;
    set[i] = false;
  }
  cin >> N >> M;
  int in0, in1;
  for (int i = 0; i < (M); ++i) {
    cin >> in0 >> in1;
    if (in0 == 1 && in1 == 0) {
      cout << "-1" << endl;
      exit(0);
    }
    if (set[in0] == true && digit[in0] != in1) {
      cout << "-1" << endl;
      exit(0);
    }
    digit[in0] = in1;
    set[in0] = true;
  }
}
void Clean() {}
int main() {
  Init();
  Solve();
  Clean();
  return 0;
}
