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