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