#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, char>> sc(m);
  for (int i = 0; i < (m); ++i) cin >> sc[i].first >> sc[i].second;
  int ans = pow(10, n - 1) - 1;
  bool a = false;
  while (ans < pow(10, n)) {
    ans++;
    string s = to_string(ans);
    int c = 0;
    for (int i = 0; i < (m); ++i) {
      if (s.at(sc[i].first - 1) == sc[i].second) c++;
    }
    if (c == m) {
      cout << (ans) << endl;
      return 0;
    }
  }
  cout << (-1) << endl;
  return 0;
}
