#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = INT_MAX;
const long long LLINF = 1LL << 60;
template <typename T_char>
char ToUpper(char cX) {
  return toupper(cX);
}
long long int digit(long long int a) {
  long long int count = 0;
  for (long long int i = 0; i < a; i++) {
    if (a == 0) {
      break;
    } else {
      a = a / 10;
      count++;
    }
  }
  return count;
}
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return a / gcd(a, b) * b;
}
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> s(n), c(m), temp(n), count(n);
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  for (int i = 0; i < n; i++) count[i] = -1;
  for (int i = 0; i < m; i++) {
    if (s[i] - 1 == 0 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (count[s[i] - 1] == -1) {
      temp[s[i] - 1] = c[i];
      count[s[i] - 1]++;
    } else {
      if (temp[s[i] - 1] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (temp[i] == -1) temp[i] = 0;
    cout << temp[i];
  }
  return 0;
}
