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