#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ;
  long long N, M;
  cin >> N >> M;
  string s, ans;
  ans = " ";
  if (N == 1) s = "0";
  if (N == 2) s = "00";
  if (N == 3) s = "000";
  for (long long i = 0; i < (long long)(M); i++) {
    long long S;
    char c;
    cin >> S >> c;
    if (S == 1 && c == '0' && N != 1) {
      ans = "-1";
      cout << "case1" << endl;
      break;
    } else if (s.at(S - 1) != c && s.at(S - 1) != '0' && s.at(S - 1) != 'a') {
      ans = "-1";
      cout << "case2" << endl;
      cout << S << ":" << s.at(S - 1) << ":" << c << endl;
      break;
    } else if (c == '0')
      s.at(S - 1) = 'a';
    else
      s.at(S - 1) = c;
  }
  if (s.at(0) == '0' && ans != "-1" && s != "0") s.at(0) = '1';
  if (ans == "-1")
    cout << ans;
  else if (s == "0")
    cout << "0";
  else {
    for (long long i = 0; i < (long long)(N); i++) {
      if (s.at(i) == 'a') s.at(i) = '0';
    }
    cout << s;
  }
}
