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