#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 60;
int main() {
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (m); i++) cin >> s[i] >> c[i];
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  string str = "";
  for (int i = 0; i < (n); i++) str.push_back('0');
  for (int i = 0; i < (m); i++) {
    str[s[i] - 1] = c[i] + '0';
  }
  if (n > 1 && str[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  cout << stoi(str) << endl;
  return 0;
}
