#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 (c > 0 && digit[s] > c) digit[s] = c;
    } else {
      if (digit[s] > c) digit[s] = c;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (digit[i] == 10) digit[i] = 0;
  }
  if (digit[1] == 0) {
    if (n == 1)
      cout << 0;
    else
      cout << -1;
  } else {
    int answer = 0;
    for (int i = 1; i <= n; i++) {
      answer *= 10;
      answer += digit[i];
    }
    cout << answer;
  }
}
