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