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