#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int a[4] = {0};
  int s, c;
  int sum = 0;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (a[s] == 0)
      a[s] = c;
    else if (a[s] != c) {
      cout << "-1" << endl;
      return 0;
    }
  }
  sum = 100 * a[1] + 10 * a[2] + a[3];
  if (n == 3 && a[1] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  if (n == 2 && a[2] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  if (n == 1 && a[3] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  cout << sum << endl;
  return 0;
}
