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