#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s, c;
  for (int i = 0; i < M; i++) {
    bool flagc = false;
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    if (tmp1 == 1 && tmp2 == 0 && N != 1) {
      cout << "-1" << endl;
      return 0;
    }
    if (i > 0) {
      for (int j = 0; j < i; j++) {
        if (tmp1 == s[j] && c[j] != tmp2) {
          cout << "-1" << endl;
          return 0;
        } else if (tmp1 == s[j] && c[j] == tmp2) {
          flagc = true;
        }
      }
    }
    if (flagc) continue;
    s.push_back(tmp1);
    c.push_back(tmp2);
  }
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    ans += pow(10, N - s[i]) * c[i];
  }
  cout << ans << endl;
  return 0;
}
