#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int m;
  int digit[4] = {10, 10, 10, 10};
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1) {
      if ((n == 1 || c > 0) && digit[s] > c) digit[s] = c;
    } else {
      if (digit[s] > c) digit[s] = c;
    }
  }
  if ((digit[1] % 10) == 0) {
    if (n == 1 && digit[1] == 0)
      cout << 0;
    else
      cout << -1;
  } else {
    int answer = 0;
    for (int i = 1; i <= n; i++) {
      answer *= 10;
      answer += (digit[i] % 10);
    }
    cout << answer;
  }
}
