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