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