#include <bits/stdc++.h>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
struct Problem {
  void Solve() {
    UL N, M;
    cin >> N >> M;
    UL C[3];
    for (UL i = 0; i < (N); i++) C[i] = -1;
    for (UL i = 0; i < (M); i++) {
      UL s, c;
      cin >> s >> c;
      if (c == 0 && s == 1 && N != 1) {
        cout << -1 << endl;
        return;
      }
      s--;
      if (C[s] != -1 && C[s] != c) {
        cout << -1 << endl;
        return;
      }
      C[s] = c;
    }
    for (UL i = 0; i < (N); i++) {
      if (C[i] == -1)
        cout << 0;
      else
        cout << C[i];
    }
    cout << endl;
  }
  Problem();
};
int main() {
  unique_ptr<Problem> p(new Problem());
  p->Solve();
  return 0;
}
Problem::Problem() { cout << fixed << setprecision(10); }
