#include <bits/stdc++.h>
using namespace std;
const int max_v = 1000;
int v, E, n, m;
int d[max_v][max_v];
int s[max_v], c[max_v];
pair<int, int> p[max_v];
const int INF = 1e9;
vector<int> ls;
void solve() {
  for (int i = 0; i + 1 < m; i++) {
    if ((p[i].first == p[i + 1].first && p[i].second != p[i + 1].second) ||
        (p[i].first == 1 && p[i].second == 0)) {
      puts("-1");
      return;
    }
  }
  if (p[m - 1].first == 1 && p[m - 1].second == 0) {
    puts("-1");
    return;
  }
  int sum = 0;
  int i = 0;
  if (p[i].first == 1) {
    sum += p[i].second * pow(10, n - 1);
  }
  while (p[i].first == 1) {
    i++;
  }
  if (p[i].first == 2 && n - 2 >= 0) {
    sum += p[i].second * pow(10, n - 2);
  }
  while (p[i].first == 2) i++;
  if (p[i].first == 3 && n - 3 >= 0) {
    sum += p[i].second * pow(10, n - 3);
  }
  if (n == 3 && sum < 100) sum += 100;
  if (n == 2 && sum < 10) sum += 10;
  cout << sum << endl;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> p[i].first >> p[i].second;
  }
  sort(p, p + m);
  solve();
  return 0;
}
