#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M];
  string a[N], p[N], c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < N; i++) {
    a[i] = "0";
    p[i] = "No";
  }
  bool judge = true;
  for (int i = 0; i < M; i++) {
    if (p[s[i] - 1] == "No") {
      a[i] = c[i];
      p[s[i] - 1] = "Yes";
    } else {
      judge = false;
    }
  }
  string ans;
  for (int i = 0; i < N; i++) {
    ans += a[i];
  }
  if (judge) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
