#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  string ans = "";
  for (int i = 0; i < (N); ++i) ans += "*";
  int S[M];
  char C[M];
  for (int i = 0; i < (M); ++i) {
    int s;
    cin >> S[i];
    char c;
    cin >> C[i];
  }
  for (int i = 0; i < (M); ++i) {
    if (ans[S[i] - 1] == '*') {
      ans[S[i] - 1] = C[i];
    } else if (ans[S[i] - 1] != C[i]) {
      cout << "-1" << endl;
      return 0;
    }
  }
  for (int i = 0; i < (N); ++i) {
    if (ans[i] == '*') {
      ans[i] = '0';
    }
  }
  if (ans[0] == '0') {
    cout << "-1" << endl;
  } else {
    cout << ans << endl;
  }
}
