#include <bits/stdc++.h>
using namespace std;
long long int dig(long long int N, long long int K) {
  long long int dig = 0;
  while (N) {
    dig++;
    N /= K;
  }
  return dig;
}
long long int gcd(long long int x, long long int y) {
  long long int r;
  while (x % y) {
    r = x % y;
    x = y;
    y = r;
  }
  return y;
}
long long int C(long long int N) { return N * (N - 1) / 2; }
const double PI = 3.14159265358979323846;
int main() {
  long long int N, M;
  cin >> N >> M;
  vector<long long int> s(M);
  vector<char> c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  string S;
  for (int i = 0; i < N; i++) S += 'a';
  for (int i = 0; i < M; i++) {
    if (S[s[i] - 1] != 'a' && S[s[i] - 1] != c[i]) {
      cout << "-1" << endl;
      return 0;
    }
    if (s[i] == 1 && c[i] == '0') {
      cout << "-1" << endl;
      return 0;
    }
    S[s[i] - 1] = c[i];
  }
  for (int i = 0; i < N; i++) {
    if (S[i] == 'a') S[i] = '0';
  }
  cout << stoi(S) << endl;
}
