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