#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s, c;
  vector<bool> used(n, false);
  vector<int> value(n, 0);
  value[0] = 1;
  for (int i = 0; i < m; ++i) {
    cin >> s >> c;
    s--;
    if (n >= 2 && (s == 0 && c == 0)) {
      cout << -1 << endl;
      return 0;
    }
    if (used[s] == true && value[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    value[s] = c;
    used[s] = true;
  }
  int ans = value[n - 1];
  int keta = 10;
  for (int k = 1; k < n; ++k) {
    ans += value[n - 1 - k] * keta;
    keta *= 10;
  }
  cout << ans << endl;
  return 0;
}
