#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; ++i) {
    cin >> s.at(i) >> c.at(i);
    s.at(i)--;
  }
  vector<int> number(N, -1);
  for (int i = 0; i < M; ++i) {
    if (number.at(s.at(i)) != 1 && number.at(s.at(i)) != c.at(i)) {
      cout << -1 << endl;
      return 0;
    } else {
      number.at(s.at(i)) = c.at(i);
    }
  }
  if (M == 0) {
    if (N == 1) cout << 0 << endl;
    if (N == 2) cout << 10 << endl;
    if (N == 3) cout << 100 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (i == 0) {
      if (number.at(i) == -1) {
        ans = 1;
      } else if (number.at(0) == 0) {
        if (N == 1) {
          cout << 0 << endl;
        } else {
          cout << -1 << endl;
        }
        return 0;
      } else
        ans = number.at(i);
    } else {
      if (number.at(i) != -1) {
        ans += number.at(i);
      }
    }
    ans *= 10;
  }
  ans /= 10;
  cout << ans << endl;
  return 0;
}
