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