#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p(m);
  int ans = 0;
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    p[i] = make_pair(s, c);
  }
  if (n > 1) {
    for (int i = 0; i < (m); ++i) {
      int a = p[i].first;
      int b = p[i].second;
      if (a == 1 && b == 0) {
        ans = -1;
        cout << ans << endl;
        return 0;
      }
      for (int j = 0; j < (m); ++j) {
        int c = p[j].first;
        int d = p[j].second;
        if (i != j && a == c && b != d) {
          ans = -1;
          cout << ans << endl;
          return 0;
        }
      }
    }
  }
  vector<bool> checked(m, true);
  for (int i = 0; i < (n); ++i) {
    int a = p[i].first;
    if (checked[a - 1]) {
      int b = p[i].second;
      ans += b * pow(10, (n - a));
      checked[a - 1] = false;
    }
  }
  cout << ans << endl;
}
