#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, s, c, ans = 0;
  map<int, int> m;
  cin >> N >> M;
  while (M--) {
    cin >> s >> c;
    if (s > N) {
      cout << "-1" << endl;
      return 0;
    }
    if (m.count(s)) {
      if (m[s] != c) {
        cout << "-1" << endl;
        return 0;
      } else {
        continue;
      }
    }
    m.insert(make_pair(s, c));
    ans += c * (int)(pow(10, N - s) + 0.5);
  }
  if (to_string(ans).size() != N) {
    cout << "-1" << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
