#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n, INF);
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (v.at(s) != INF && v.at(s) != c) {
      cout << -1 << endl;
      return 0;
    }
    if (s == 0 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    v.at(s) = c;
  }
  int ans = 0;
  for (int i = 0; i < (n); ++i) {
    if (i == 0 && v.at(i) == INF)
      ans += pow(10, n - 1);
    else if (i > 0 && v.at(i) == INF)
      ans += 0;
    else
      ans += pow(10, n - 1 - i) * v.at(i);
  }
  cout << ans << endl;
}
