#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (int)(m); i++) cin >> s[i] >> c[i];
  int res_num = 0;
  int res = 0;
  vector<int> pas_(m, 0);
  int fla = 0;
  for (int i = 0; i < (int)(m); i++) {
    for (int j = i + 1; j < m; j++) {
      if (s[i] == s[j]) {
        if (c[i] == c[j])
          pas_[j] = -1;
        else {
          res = -1;
          break;
        }
      }
    }
    if (res == -1) continue;
    if (pas_[i] == -1) continue;
    if (n - s[i] != 0 && c[i] == 0)
      res = -1;
    else {
      for (int k = 0; k < (int)(n - s[i]); k++) c[i] = c[i] * 10;
      res_num += c[i];
      if (s[i] == 1) fla = 1;
    }
  }
  if (fla == 0) res_num += 1 * pow(10, n - 1);
  if (res == -1)
    cout << res;
  else
    cout << res_num;
  return 0;
}
