#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  short negative = 1;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') negative = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  x *= negative;
}
int main() {
  int n, m;
  int ans = 0;
  bool flag[3];
  cin >> n >> m;
  for (int i = 0, _n = m; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0 && n != 1) {
      cout << -1 << endl;
      return 0;
    }
    if (s == 1)
      if (flag[s] == 1 && ((ans / 100 != c && n == 3) ||
                           (ans / 10 != c && n == 2) || ans != c && n == 1)) {
        cout << -1 << endl;
        return 0;
      } else if (flag[s] == 0) {
        ans += 100 * c;
        flag[s] = 1;
      }
    if (s == 2)
      if (flag[s] == 1)
        if (n == 3 && n % 100 / 10 != c || n == 2 && n / 10) {
          cout << -1 << endl;
          return 0;
        } else if (flag[s] == 0) {
          ans += 10 * c;
          flag[s] = 1;
        }
    if (s == 3)
      if (flag[s] == 1 && ans % 10 != c) {
        cout << -1 << endl;
        return 0;
      } else if (flag[s] == 0) {
        ans += c;
        flag[s] = 1;
      }
  }
  cout << ans << endl;
  return 0;
}
