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