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