#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], c[M];
    for (long long i = 0; i < (M); ++i) in >> s[i] >> c[i];
    int ans[N];
    for (long long i = 0; i < (N); ++i) ans[i] = 10;
    bool ok = true;
    for (long long i = 0; i < (M); ++i) {
      if (s[i] == 1 && c[i] == 0) {
        ok = false;
        break;
      }
      if (ans[s[i] - 1] != 10 && ans[s[i] - 1] != c[i]) {
        ok = false;
        break;
      }
      ans[s[i] - 1] = c[i];
    }
    if (ok) {
      for (long long i = 0; i < (N); ++i) {
        if (ans[i] == 10) {
          if (i == 0) {
            ans[i] = 1;
          } else {
            ans[i] = 0;
          }
        }
        out << ans[i];
      }
    } else {
      out << -1;
    }
    out << '\n';
  }
};
int main() {
  CGuessTheNumber solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
