#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<set<int>> A(N);
  for (int n = 0; n < M; ++n) {
    int s, c;
    cin >> s >> c;
    A[s - 1].insert(c);
  }
  int ans = 0;
  for (int n = 0; n < N; ++n) {
    int num = 0;
    if (A[n].size() > 1) {
      cout << "-1" << endl;
      return 0;
    }
    if (A[n].size() == 1) {
      num = *A[n].begin();
    }
    if (num == 0 && 0 == n) {
      if (1 != N) {
        num = 1;
      }
    }
    ans = 10 * ans + num;
  }
  cout << ans << endl;
  return 0;
}
