#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(6);
  cout << fixed;
  string res = "";
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) res += '0';
  bool bad = false;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (s == 0 && c == 0) bad = true;
    if (mp.find(s) != mp.end()) {
      if (mp[s] != c) bad = true;
    } else {
      mp[s] = c;
      res[s] = c + '0';
    }
  }
  if (bad)
    cout << -1 << '\n';
  else
    cout << res << '\n';
  return 0;
}
