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