#include <bits/stdc++.h>
using namespace std;
const long long nmax = 1e9 + 7;
const long long Mod = 998244353;
const double PI = 2 * asin(1);
int digit_cnt(int N) {
  if (N == 0)
    return 1;
  else {
    int ans = 0;
    while (N > 0) {
      ans++;
      N /= 10;
    }
    return ans;
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<bool> visited(N);
  vector<int> ans(N);
  for (int i = 0; i < M; i++) {
    int S, C;
    cin >> S >> C;
    S--;
    if (visited[S] == false) {
      visited[S] = true;
      ans[S] = C;
    } else {
      if (ans[S] != C) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (visited[i] == false) {
      if (i == 0)
        cout << 1;
      else
        cout << 0;
    } else {
      if (i == 0 && ans[i] == 0) {
        cout << -1 << endl;
        return 0;
      }
      cout << ans[i];
    }
  }
  cout << endl;
  return 0;
}
