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