#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 = "";
  for (int i = 0; i < n; i++) s += 'a';
  for (int i = 0; i < m; i++) {
    int si;
    char c;
    cin >> si >> c;
    if (c != '0') s[si - 1] = min(c, s[si - 1]);
  }
  for (int i = 0; i < n; i++)
    if (s[i] == 'a') s[i] = '0';
  if (s.length() != 1 && s[0] == '0')
    cout << "-1\n";
  else
    cout << s << "\n";
  return 0;
}
