#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7ll;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const long long inf = 1ll << 60;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> check(50, -1);
  bool flag = false;
  int ans = 0;
  if (m == 0) {
    if (n == 1)
      cout << 0 << endl;
    else if (n == 2)
      cout << 10 << endl;
    else if (n == 3)
      cout << 100 << endl;
    return 0;
  } else {
    for (int i = 0; i < m; i++) {
      int s, c;
      cin >> s >> c;
      if (s == 1 and c == 0)
        flag = true;
      else if (check.at(s) >= 0 and check.at(s) != c)
        flag = true;
      else if (check.at(s) >= 0 and check.at(s) == c)
        continue;
      else {
        check.at(s) = c;
        for (int i = 0; i < n - s; i++) c *= 10;
        ans += c;
      }
    }
    if (check.at(1) == -1) {
      int c = 1;
      for (int i = 0; i < n - 1; i++) c *= 10;
      ans += c;
    }
    if (flag) {
      cout << -1 << endl;
      return 0;
    }
    cout << ans << endl;
    return 0;
  }
}
