#include <bits/stdc++.h>
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
using long long int = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
class Solve {
 public:
  void solve() {
    Int N, M;
    cin >> N >> M;
    vector<Int> dig(N, -1);
    for (int i = 0; i < M; ++i) {
      Int s, c;
      cin >> s >> c;
      if (dig[s - 1] == -1 || dig[s - 1] == c) {
        dig[s - 1] = c;
      } else {
        cout << -1 << endl;
        return;
      }
      if (s == 1 && dig[s - 1] == 0) {
        cout << -1 << endl;
        return;
      }
    }
    for (int i = 0; i < N; ++i) {
      if (dig[i] == -1) {
        if (i == 0) {
          dig[i] = 1;
        } else {
          dig[i] = 0;
        }
      }
    }
    Int ans = 0;
    for (int i = 0; i < N; ++i) {
      ans *= 10;
      ans += dig[i];
    }
    cout << ans << endl;
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  Solve().solve();
  return 0;
}
