#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  set<int> S[N];
  for (int i = (0); i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    S[s].insert(c);
  }
  long long ans = 0;
  for (int i = (0); i < (N); ++i) {
    ans *= 10;
    if (S[i].size() > 1) {
      cout << -1 << endl;
      return 0;
    } else if (S[i].size() == 1) {
      if (i == 0 and *(S[i].begin()) == 0) {
        cout << -1 << endl;
        return 0;
      }
      ans += *(S[i].begin());
    } else {
      if (i == 0) ans += 1;
    }
  }
  cout << ans << endl;
  return 0;
}
