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