#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> num(N, vector<int>(2));
  num.at(0).at(0) = 1;
  num.at(0).at(1) = 0;
  bool ans = true;
  for (int i = 1; i < N; i++) {
    num.at(i).at(0) = 0;
    num.at(i).at(1) = 0;
  }
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (num.at(s - 1).at(1) > 0) {
      if (num.at(s - 1).at(0) != c) {
        ans = false;
      }
    }
    num.at(s - 1).at(0) = c;
    num.at(s - 1).at(1)++;
  }
  if (num.at(0).at(0) == 0 && N != 1) ans = false;
  int x = 1;
  if (ans) {
    x = num.at(0).at(0);
    if (N > 1) {
      for (int i = 1; i < N; i++) {
        x *= 10;
        x += num.at(i).at(0);
      }
    }
  } else {
    x = -1;
  }
  cout << x << endl;
  return 0;
}
