#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  string s = "###";
  for (int i = 1; i <= m; i++) {
    int pos;
    char c;
    cin >> pos >> c;
    --pos;
    if (s[pos] != '#' && c != s[pos]) cout << -1, exit(0);
    s[pos] = c;
  }
  if (s[0] == '#' || s[0] == '0') cout << -1, exit(0);
  cout << s[0];
  if (s[1] == '#')
    cout << '0';
  else
    cout << s[1];
  if (s[2] == '#')
    cout << 0;
  else
    cout << s[2];
  return 0;
}
