#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
using M = map<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  for (int i = 0; i < (int)(n); i++) v[i] = -1;
  int a, b, ok = 0;
  int ans = 0;
  for (int i = 0; i < (int)(m); i++) {
    cin >> a >> b;
    if (n == 1) {
      v[0] = b;
    } else {
      if (v[a - 1] == -1) v[a - 1] = b;
      if (v[a - 1] != b) ans = -1;
    }
  }
  for (int i = 0; i < (int)(n); i++) {
    if (v[i] == -1) v[i] = 0;
  }
  if (ans > -1) {
    if (n == 1) {
      cout << v[0] << endl;
      return 0;
    }
    if (n > 1 && v[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    for (int i = 0; i < (int)(n); i++) {
      ans *= 10;
      ans += v[i];
    }
  }
  cout << ans << endl;
  return 0;
}
