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