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