#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, s, c, ans = 0;
  cin >> N >> M;
  bool st_flag = false, dup_flag = false;
  vector<pair<int, int> > pairs;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    pairs.push_back(make_pair(s, c));
    if (s == 1 && c != 0) {
      st_flag = true;
    }
    for (int j = 0; j < pairs.size(); j++) {
      if (pairs[j].first == s && pairs[j].second != c) {
        dup_flag = true;
        break;
      }
    }
  }
  sort((pairs).begin(), (pairs).end());
  if (st_flag && !dup_flag) {
    int pre = 0;
    for (int i = 0; i < pairs.size(); i++) {
      if (pre != pairs[i].first) {
        ans += pairs[i].second * pow(10, N - pairs[i].first);
        pre = pairs[i].first;
      }
    }
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
