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