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