#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n, max = 1, b[3] = {10};
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
    if (max < s[i]) max = s[i];
    b[s[i] - 1] = c[i];
  }
  if (max != n || (b[0] == 0 && n != 1)) {
    cout << -1 << endl;
    return 0;
  }
  if (b[0] == 10) b[0] = 1;
  int ans;
  ans = b[0] * pow(10, n - 1) + (b[1] % 10) * pow(10, n - 2) +
        (b[2] % 10) * pow(10, n - 3);
  cout << ans << endl;
  return 0;
}
