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