#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
const long double eps = 1e-10;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> S(m), C(m), D(n, -1);
  for (int i = (int)(0); i < (int)(m); i++) {
    cin >> S[i] >> C[i];
    S[i]--;
    if (D[S[i]] == -1)
      D[S[i]] = C[i];
    else if (D[S[i]] != C[i]) {
      cout << -1 << "\n";
      return 0;
    }
  }
  long long ans = 0;
  for (int i = (int)(0); i < (int)(n); i++) {
    if (D[i] == -1) {
      if (i == 0)
        D[i] = 1;
      else
        D[i] = 0;
    } else if (n != 1 && i == 0 && D[i] == 0) {
      cout << -1 << "\n";
      return 0;
    }
    ans += D[i] * pow(10, m - 1 - i);
  }
  cout << ans << "\n";
  return 0;
}
