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