#include <bits/stdc++.h>
using namespace std;
int ANS[5];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    ANS[i] = -1;
  }
  bool ans = true;
  for (int j = 0; j < m; j++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      ans = false;
      break;
    }
    if (ANS[s] >= 0 && c != ANS[s]) {
      ans = false;
      break;
    }
    ANS[s] = c;
  }
  if (n > 1 && ANS[1] == -1) ANS[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (ANS[i] == -1) ANS[i] = 0;
  }
  int D = 1;
  int tot = 0;
  for (int i = n; i > 0; i--) {
    tot += ANS[i] * D;
    D *= 10;
  }
  if (n == 1 && ANS[1] == -1) tot = 0;
  if (ans)
    cout << tot << endl;
  else
    cout << -1 << endl;
  return 0;
}
