#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = (0); i < (m); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  int ans[n];
  for (int i = (0); i < (n); i++) ans[i] = -1;
  int error = 0;
  if (m == 0) error = -1;
  for (int i = (0); i < (m); i++) {
    if (ans[s[i]] == -1 || ans[s[i]] == c[i])
      ans[s[i]] = c[i];
    else
      error = 1;
  }
  int ANS = 0;
  if (ans[0] == -1)
    ans[0] = 1;
  else if (ans[0] == 0 && n != 1)
    error = 1;
  for (int i = (1); i < (n); i++)
    if (ans[i] == -1) ans[i] = 0;
  int ten = 1;
  if (error == 0) {
    for (int i = n - 1; i >= 0; i--) {
      ANS += ans[i] * ten;
      ten *= 10;
    }
  }
  if (error)
    cout << -1 << endl;
  else
    cout << ANS << endl;
  return 0;
}
