#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i;
  cin >> n >> m;
  int s, c;
  int res[4];
  for (i = 1; i <= 3; i++) res[i] = -1;
  bool flag = false;
  for (i = 0; i < m; i++) {
    cin >> s >> c;
    if (s > n) {
      flag = true;
      break;
    }
    if (res[s] == -1)
      res[s] = c;
    else {
      if (res[s] != c) {
        flag = true;
        break;
      }
    }
  }
  if (flag || ((res[1] == -1 || res[1] == 0) && n > 1))
    cout << "-1";
  else if (m == 0 && n == 1)
    cout << "-1";
  else {
    int digit = 0;
    for (i = 1; i <= n; i++) {
      if (res[i] == -1) res[i] = 0;
      digit = digit * 10 + res[i];
    }
    if (digit == 0 && n > 1)
      cout << "-1";
    else
      cout << digit;
  }
  return 0;
}
