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