#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> pairs(m);
  long long s[m];
  long long c[m];
  vector<long long> h(n, -1);
  vector<char> cs(n, '0');
  string ans;
  for (int i = 0; i < (m); i++) {
    cin >> pairs[i].first >> pairs[i].second;
    cs[--pairs[i].first] = pairs[i].second + '0';
  }
  for (int i = 0; i < (m); i++) {
    if (h[pairs[i].first] == -1)
      h[pairs[i].first] = pairs[i].second;
    else if (h[pairs[i].first] != pairs[i].second) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (cs[0] == '0' && n > 1) {
    cout << -1 << endl;
    return 0;
  }
  for (char tmp : cs) ans.push_back(tmp);
  cout << ans << endl;
  return 0;
}
