#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using G = vector<vector<int>>;
int main() {
  int c_flag[3] = {0};
  int n, m, count = 1, ans = 0;
  cin >> n >> m;
  vector<int> s(m, 0);
  vector<int> c(m, 0);
  int keta[3] = {100, 10, 1};
  for (int i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  for (int i = 0; i < m; i++) {
    if ((c_flag[s[i] - 1] != 0) && (c_flag[s[i] - 1] != c[i])) {
      ans = 1000;
      break;
    } else {
      if (c_flag[s[i] - 1] == c[i]) continue;
      ans += (keta[s[i] - 1] * c[i]);
      c_flag[s[i] - 1] = c[i];
    }
  }
  string str = to_string(ans);
  int len = str.size();
  if (ans > 999 || len != n)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
