#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  unordered_map<int, int> F;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (F.find(s - 1) != F.end()) {
      if (F[s - 1] != c) {
        cout << -1 << endl;
        return;
      }
    } else {
      F[s - 1] = c;
    }
  }
  for (int i = min(0, (int)pow(10, n - 1)); i < pow(10, n); i++) {
    string num = to_string(i);
    bool found = true;
    for (auto it = F.begin(); it != F.end(); it++) {
      if (it->second != num[it->first] - '0') {
        found = false;
        break;
      }
    }
    if (found) {
      cout << i << endl;
      return;
    }
  }
  cout << -1 << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}
