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