#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> keta(n, -1);
  for (int i = 0; i < m; i++) {
    int s;
    cin >> s;
    s--;
    int c;
    cin >> c;
    if (keta[s] != -1 && keta[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    keta[s] = c;
  }
  if (n >= 2 && keta[0] <= 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans *= 10;
    if (keta[i] != -1) {
      ans += keta[i];
    }
  }
  cout << ans << endl;
  return 0;
}
