#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const long MOD = 998244353;
const long mod1 = 1000000007;
void solve() {
  int n, m, i, flag = 0;
  cin >> n >> m;
  vector<int> final(n, 0);
  for (i = 1; i <= m; i++) {
    int s, c;
    cin >> s >> c;
    if (s - 1 == 0 && c == 0)
      flag = 1;
    else {
      if (final[s - 1] == 0 || final[s - 1] == c)
        final[s - 1] = c;
      else
        flag = 1;
    }
  }
  if (flag == 1)
    cout << "-1";
  else {
    for (i = 0; i < n; i++) cout << final[i];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long t = 1;
  while (t--) solve();
  return 0;
}
