#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m);
  vector<long long> c(m);
  ;
  for (long long i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<long long> d(n);
  ;
  for (long long i = 0; i < (n); i++) d[i] = 0;
  d[0] = 1;
  vector<bool> check(n, false);
  ;
  for (long long i = 0; i < (m); i++) {
    if (check[s[i]] && d[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    } else if (s[i] == 0 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    } else {
      d[s[i]] = c[i];
      check[s[i]] = true;
    }
  };
  for (long long i = 0; i < (n); i++) cout << d[i];
  cout << endl;
}
