#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int m;
  map<int, int> p;
  int s, c;
  int ans = 0;
  cin >> n;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (s == 1 && c == 0 && n >= 2) {
      ans = -1;
      break;
    } else if (p.count(s) && p[s] != c) {
      ans = -1;
      break;
    } else if (p.count(s) && p[s] == c) {
      ;
    } else {
      int k = 1;
      p[s] = c;
      for (int i = 1; i <= n - s; i++) {
        k *= 10;
      }
      ans += c * k;
    }
  }
  cout << ans << endl;
}
