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