#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int main() {
  int N, M;
  cin >> N >> M;
  int S[M];
  string C[M];
  for (int i = 0; i < (M); i++) cin >> S[i] >> C[i];
  string s = "";
  for (int i = 0; i < (N); i++) s += "0";
  for (int i = 0; i < (M); i++) {
    if ((s[S[i] - 1] != '0') && (s[S[i] - 1] != C[i][0])) {
      cout << "-1"
           << "\n";
      ;
      return 0;
    }
    s[S[i] - 1] = C[i][0];
  }
  if (s[0] == '0')
    cout << "-1"
         << "\n";
  else
    cout << s << "\n";
}
