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