#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > sc(m);
  for (int i = 0; i < (m); i++) cin >> sc[i].first >> sc[i].second;
  for (int i = 0; i < (1000); i++) {
    bool f = true;
    for (auto p : sc) {
      string s = to_string(i);
      if (s.size() != n) f = false;
      if (!(s[p.first - 1] == (char)('0' + p.second))) f = false;
    }
    if (f) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
