#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> p;
  int s, c;
  bool flag = 1;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    bool flag2 = 1;
    for (int j = 0; j < p.size(); j++) {
      if (p[j].first == s && p[j].second != c) flag = 0;
      if (p[j].first == s || s > n) flag2 = 0;
    }
    if (s == 1 && c == 0) flag = 0;
    if (flag2) p.push_back(make_pair(s, c));
  }
  if (flag) {
    sort(p.begin(), p.end());
    int ans = 0;
    if (p[0].first > 1) ans += pow(10, n - 1);
    for (int i = 0; i < p.size(); i++)
      ans += pow(10, n - p[i].first) * p[i].second;
    cout << ans << endl;
  } else
    cout << -1 << endl;
}
