#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vs(m, 0);
  vector<int> vc(m, 0);
  for (int i = 0; i < m; i++) {
    int t1, t2;
    cin >> t1 >> t2;
    vs[i] = t1 - 1;
    vc[i] = t2;
  }
  vector<int> ans(n, INT_MAX);
  for (int i = 0; i < m; i++) {
    if (ans[vs[i]] == INT_MAX) {
      ans[vs[i]] = vc[i];
    }
    if (ans[vs[i]] != vc[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ans[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (ans[0] == INT_MAX) {
    ans[0] = 1;
  }
  int result = 0;
  for (int i = 0; i < n; i++) {
    if (ans[i] == INT_MAX) {
      ans[i] = 0;
    }
    result = result * 10 + ans[i];
  }
  cout << result << endl;
  return 0;
}
