#include <bits/stdc++.h>
using namespace std;

int main()
{
  int N, M;
  int ans = -1;
  cin >> N >> M;
  vector<pair<int, char>> sc(M);
  for (int i = 0; i < M; ++i) {
    cin >> sc[i].first >> sc[i].second;
  }
  for (int i = pow(10, N-1)-1, ma = pow(10, N); i < ma; ++i) {
    bool flag = 1;
    string s = to_string(i);
    if (int(s.size()) != N) continue;
	for (int j = 0; j < M; ++j) {
	  if (s[sc[j].first-1] != sc[j].second) {flag = 0; break;}
    }
    if (flag) {ans = i; break;}
  }
  cout << ans << "\n";
}