#include <bits/stdc++.h>
using namespace std;
int main() {
  int keta;
  int kazu;
  int s[kazu];
  int c[kazu];
  int check[kazu];
  int i;
  int ans;
  cin >> keta >> kazu;
  for (i = 0; i < kazu; i++) {
    cin >> s[i] >> c[i];
  }
  for (i = 0; i < kazu; i++) {
    if (s[i] == 1 && c[i] == 0) {
      ans = -1;
      cout << ans << endl;
      return 0;
    }
  }
  int j = 0;
  for (i = 0; i < kazu - 1; i++) {
    for (j = i + 1; j < kazu; j++) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) {
          ans = -1;
          cout << ans << endl;
          return 0;
        }
      }
    }
  }
  for (i = 0; i < kazu; i++) {
    if (check[i] == 100) {
      continue;
    }
    for (j = 0; j < keta - s[i]; j++) {
      c[i] *= 10;
    }
    ans += c[i];
    check[s[i]] = 100;
  }
  cout << ans << endl;
  return 0;
}
