#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  for (int i = 0; i < (m); i++) cin >> s[i] >> c[i];
  for (int i = 0; i < (m); i++) {
    if (s[i] == 1 && c[i] == 0 && n != 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  map<long long, long long> mp;
  for (int i = 0; i < (m); i++) {
    if (mp.find(s[i]) != mp.end() && mp[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    } else {
      mp[s[i]] = c[i];
    }
  }
  if (n == 1 && mp[1] == 0) {
    cout << 0 << endl;
    return 0;
  }
  string ans = "";
  if (mp.find(1) == mp.end())
    ans = "1";
  else
    ans = to_string(mp[1]);
  for (int i = 2; i <= n; ++i) {
    if (mp.find(mp[i]) != mp.end())
      ans = ans + to_string(mp[i]);
    else
      ans = ans + "0";
  }
  cout << ans << endl;
  return 0;
}
