#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to;
  int weight;
  edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<int>>;
const int INF = 2000000000;
const long long INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const long long MOD = 1000000007LL;
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> s(m), c(m);
  for (int i = 0; i < (int)(m); i++) std::cin >> s[i] >> c[i];
  std::vector<int> a(n, -1);
  for (int i = 0; i < (int)(m); i++) {
    if (a[s[i] - 1] == -1)
      a[s[i] - 1] = c[i];
    else {
      if (a[s[i] - 1] == c[i])
        continue;
      else {
        std::cout << -1 << std::endl;
        exit(0);
      }
    }
  }
  if (a[0] == 0) {
    std::cout << -1 << std::endl;
    exit(0);
  } else if (a[0] == -1) {
    std::cout << 1;
  } else
    std::cout << a[0];
  for (int i = 1; i < (int)(n); i++) {
    if (a[i] == -1)
      std::cout << 0;
    else
      std::cout << a[i];
  }
  std::cout << std::endl;
}
