#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(m);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    p[i] = make_pair(s, c);
  }
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      if (p[i].first == p[j].first) {
        if (p[i].second != p[j].second) {
          cout << -1 << endl;
          return 0;
        }
        p[j].second = 0;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    ans += p[i].second * pow(10, n - p[i].first);
  }
  cout << ans + 1 << endl;
}
