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