#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.at(i) >> c.at(i);
  }
  string ans;
  ans.assign(n, '0');
  for (int i = 0; i < m; i++) {
    if (ans.at(s.at(i) - 1) != '0' &&
        ans.at(s.at(i) - 1) != to_string(c.at(i)).at(0)) {
      cout << -1 << endl;
      return 0;
    }
    ans.at(s.at(i) - 1) = to_string(c.at(i)).at(0);
  }
  if (ans.at(0) == '0') {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
}
