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