#include <bits/stdc++.h>
using namespace std;
constexpr int inf = 0x3f3f3f3f;
constexpr long long INF = 9123456789123456789;
constexpr long long MOD = 1000000007LL;
int N, M;
void sol() {}
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  cin.tie(nullptr);
  cin >> N >> M;
  vector<int> num(N, -1);
  bool chk(false);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (num[s] >= 0)
      if (num[s] != c) {
        cout << "-1\n";
        return 0;
      }
    num[s] = c;
  }
  if (num[0] == 0) {
    cout << "-1\n";
    return 0;
  }
  if (num[0] == -1 && N > 1) num[0] = 1;
  string s;
  for (int i = 0; i < N; i++) {
    if (num[i] == -1)
      s += '0';
    else
      s += ('0' + num[i]);
  }
  cout << s << endl;
  return 0;
}
