#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[i] >> c[i];
  vector<int> ans(n, 10);
  bool ok = true;
  for (int i = 0; i < m; i++) {
    int k = ans[s[i] - 1];
    if (k < 10 && k != c[i])
      ok = false;
    else
      ans[s[i] - 1] = c[i];
  }
  if (ok) {
    if (ans[0] == 0 && n > 1)
      cout << -1 << endl;
    else {
      for (int i = 0; i < n; i++) {
        if (i == 0 && ans[i] == 10)
          ans[i] = 1;
        else if (ans[i] == 10)
          ans[i] = 0;
        cout << ans[i];
      }
      cout << endl;
    }
  } else
    cout << -1 << endl;
}
