#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
int ctoi(char c) { return c - '0'; }
class CGuessTheNumber {
 public:
  void solve(std::istream& in, std::ostream& out) {
    int N, M;
    in >> N >> M;
    int s[M];
    char c[M];
    for (long long i = 0; i < (M); ++i) in >> s[i] >> c[i];
    int ans = -1;
    int temp = 1;
    for (long long i = 0; i < (N); ++i) temp *= 10;
    for (int i = 0; i < temp; ++i) {
      if (N > 2) {
        if (i < temp / 10) continue;
      }
      string t = to_string(i);
      bool ok = true;
      for (long long j = 0; j < (M); ++j) {
        if (t[s[j] - 1] != c[j]) ok = false;
      }
      if (ok) {
        ans = i;
        break;
      }
    }
    out << ans << '\n';
  }
};
int main() {
  CGuessTheNumber solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
