#include <bits/stdc++.h>
using namespace std;
long long gcd(long x, long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long lcm(long x, long y) { return x * y / gcd(x, y); }
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int main() {
  int N, M, s[10] = {};
  char c[10] = {};
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = pow(10.0, N - 1); i < pow(10.0, N); i++) {
    int f = 0;
    string S = to_string(i);
    for (int i = 0; i < M; i++) {
      if (S[s[i] - 1] != c[i]) {
        f = 1;
        break;
      }
    }
    if (f == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
