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