#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  char c[m];
  string ans;
  int p = pow(10, n);
  ans = to_string(p);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < m; i++) {
    if (s[i] == 1 && c[i] == '0') {
      cout << "-1";
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (!(ans[s[i]] == '0') && !(ans[s[i]] == c[i])) {
      cout << "-1";
      return 0;
    }
    ans[s[i]] = c[i];
  }
  if (ans[1] = '0' && n == 3) ans[1] = '1';
  if (ans[2] = '0' && n == 3) ans[2] = '1';
  if (ans[1] = '0' && n == 2) ans[1] = '0';
  cout << stoi(ans) - p;
}
