#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long mod = 1e9 + 7;
using Graph = vector<vector<int>>;
int main() {
  int M, N;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < (M); ++i) cin >> s[i] >> c[i];
  for (int i = 0; i < (M); ++i) s[i]--;
  int used[N];
  for (int i = 0; i < (N); ++i) used[i] = -1;
  bool can = true;
  for (int i = 0; i < (M); ++i) {
    if (s[i] == 0 && c[i] == 0) can = false;
    if (used[s[i]] != -1 && used[s[i]] != c[i])
      can = false;
    else
      used[s[i]] = c[i];
  }
  if (used[0] == -1) used[0] = 1;
  if (!can)
    cout << -1 << endl;
  else {
    int ans = 0;
    for (int i = 0; i < (N); ++i) {
      int d = N - i;
      d--;
      if (used[i] == -1)
        continue;
      else {
        ans += used[i] * pow(10, d);
      }
    }
    cout << ans << endl;
  }
}
