#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int INF = 1e9;
const lint LINF = 1e18;
const lint MOD = 1e9 + 7;
const double EPS = 1e-10;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> Num(n, -1);
  for (int i = (int)(0); i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    if (Num[s - 1] == -1 or Num[s - 1] == c) {
      Num[s - 1] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  bool notZero = true;
  for (int i = (int)(0); i < (int)(n); i++) {
    if (Num[i] == 0 and i != n - 1) {
      cout << -1 << endl;
      return 0;
    } else {
      break;
    }
  }
  for (int i = (int)(0); i < (int)(n); i++) {
    if (Num[i] == -1) {
      Num[i] = 0;
    }
  }
  int mul = 1;
  int ans = 0;
  for (int i = (int)(0); i < (int)(n); i++) {
    ans += Num[n - i - 1] * mul;
    mul *= 10;
  }
  cout << ans << endl;
  return 0;
}
