#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long int ans = 0;
  long long int n, m;
  cin >> n >> m;
  int *c, *cc;
  c = new int[n];
  cc = new int[n];
  for (int i = 0; i < n; i++) {
    c[i] = 0;
    cc[i] = 0;
  }
  c[0] = 1;
  for (int i = 0; i < m; i++) {
    int s, t;
    cin >> s >> t;
    if (cc[s - 1] == 1 && c[s - 1] != t) {
      cout << -1 << endl;
      return 0;
    } else {
      c[s - 1] = t;
      cc[s - 1] = 1;
    }
  }
  if (c[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int pow = 1;
  for (int i = 0; i < n; i++) {
    ans += c[n - i - 1] * pow;
    pow *= 10;
  }
  cout << ans << endl;
}
