#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ans(N, -1);
  for (int i = 0; i < M; i++) {
    int b, c;
    cin >> b >> c;
    b--;
    if (!(b + c)) {
      cout << -1 << endl;
      return 0;
    }
    if (ans[b] != c && ans[b] != -1) {
      cout << -1 << endl;
      return 0;
    }
    ans[b] = c;
  }
  int answer = 0;
  for (int i = 0; i < N; i++) {
    if (ans[i] == -1) ans[i] = 0;
    answer *= 10;
    answer += ans[i];
  }
  cout << answer << endl;
}
