#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> a;
  for (int i = 0; i < m; i++) {
    int b, c;
    cin >> b >> c;
    if (a.count(b) && a[b] != c) {
      cout << -1 << endl;
      return 0;
    }
    a[b] = c;
  }
  int sum = 0;
  if (n != 1 && a[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < n - i; j++) {
      if (i != 1 && sum == 0) {
        cout << -1 << endl;
        return 0;
      }
      a[i] *= 10;
    }
    sum += a[i];
  }
  cout << sum << endl;
}
