#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s[6] = {0}, f = 0, flag = 0, c[6] = {0}, i, j, b = 0, x;
  cin >> n >> m;
  for (i = 1; i <= m; i++) {
    cin >> s[i] >> c[i];
    for (j = 0; j < i; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        f = 1;
        break;
      } else if (s[i] == s[j]) {
        flag = 1;
        break;
      }
      if (s[i] == 1 && c[i] == 0 && n != 1) {
        f = 1;
        break;
      }
    }
    if (flag == 0) {
      x = 1;
      for (int k = 1; k <= n - s[i]; k++) x *= 10;
      b += c[i] * x;
    } else if (f == 1) {
      break;
    } else {
      flag = 0;
    }
  }
  if (f == 1) {
    cout << -1;
    return 0;
  }
  cout << b;
  return 0;
}
