#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const long long BIG = 1000000007;
const double PI = 3.141592653589793;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < (m); i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < (1000); i++) {
    string str = to_string(i);
    bool match = true;
    for (int j = 0; j < (m); j++) {
      if (str[s[j] - 1] != c[j]) match = false;
    }
    if (n > 2 && str[0] == '0') match = false;
    if (match) {
      cout << str << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
