#include <bits/stdc++.h>
using namespace std;
void g_dir(vector<vector<pair<long long, long long> > > &graph, long long a,
           long long b, long long w = 1) {
  graph[a].push_back(pair<long long, long long>(b, w));
}
void g_undir(vector<vector<pair<long long, long long> > > &graph, long long a,
             long long b, long long w = 1) {
  g_dir(graph, a, b, w);
  g_dir(graph, b, a, w);
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
  }
}
template <class T>
void chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
  }
}
const long long INF = 1145141919;
const long long MOD = 1000000007;
const long long NUM = 101010;
int main() {
  long long N, M;
  cin >> N >> M;
  long long S[5], C[5];
  for (long long(i) = 0; (i) < (M); (i)++) cin >> S[i] >> C[i];
  for (int i = 0; i < 1000; i++) {
    vector<long long> v;
    for (int j = i; j; j /= 10) v.push_back(j % 10);
    if (v.size() == 0) v.push_back(0);
    reverse(v.begin(), v.end());
    int f = 1;
    for (long long(j) = 0; (j) < (M); (j)++)
      if (v[S[j] - 1] != C[j]) f = 0;
    if (f) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
