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