#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, m;
  cin >> n >> m;
  string s;
  string ans;
  unordered_map<int, char> mp;
  for (int i = 0; i < n; i++) s += "0";
  while (m--) {
    int i;
    char c;
    cin >> i >> c;
    if (mp.find(i) == mp.end()) {
      mp[i] = c;
      s[i - 1] = c;
    } else {
      ans = "-1";
      break;
    }
  }
  if (s[0] == '0' && n != 1)
    ans = "-1";
  else
    ans = s;
  cout << ans << "\n";
  return 0;
}
