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