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