#include <bits/stdc++.h>
using namespace std;
int main() {
  int s[10];
  char c[10];
  int M, N;
  int i;
  int cnt = 0;
  cin >> N >> M;
  for (i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  string a(N, '0');
  for (i = 0; i < M; i++) {
    int k = s[i];
    if (a[k - 1] != '0' && a[k - 1] != c[i])
      cnt = -1;
    else
      a[k - 1] = c[i];
  }
  if (cnt == -1 || a[0] == '0')
    cout << -1 << endl;
  else
    cout << a << endl;
  return 0;
}
