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