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