#include <bits/stdc++.h>
using namespace std;
long long mod = 1e+9 + 7;
int main() {
  int N, M;
  bool flag = true;
  vector<int> X(3, 0);
  cin >> N >> M;
  int s[M], c[M];
  for (long long i = 0; i < (long long)(M); i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 and c[i] == 0) flag = false;
    if (X[s[i] - 1] == 0)
      X[s[i] - 1] = c[i];
    else if (X[s[i] - 1] != 0 and X[s[i] - 1] == c[i])
      continue;
    else
      flag = false;
  }
  if (flag) {
    int ans = 0;
    for (long long i = 0; i < (long long)(3); i++) {
      ans += pow(10, N - i - 1) * X[i];
    }
    if (X[3 - N] == 0) {
      ans += pow(10, N - 1);
    }
    cout << ans << endl;
  } else
    cout << -1 << endl;
  return 0;
}
