#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> vp(4);
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    if (vp[s].second > 0 && vp[s].first == c)
      continue;
    else
      vp[s].first = c;
    vp[s].second++;
  }
  for (auto x : vp)
    if (x.second > 1) {
      cout << -1 << endl;
      return 0;
    }
  int ans = vp[1].first * 100;
  ans += vp[2].first * 10;
  ans += vp[3].first;
  string s = to_string(ans);
  if (s.size() != n)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
