using System;
using System.Collections.Generic;
using CompLib.Util;

public class Program
{
    private int N;
    private long[] X, Y;
    private char[] U;

    private long Ans;


    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        X = new long[N];
        Y = new long[N];
        U = new char[N];
        for (int i = 0; i < N; i++)
        {
            X[i] = sc.NextInt();
            Y[i] = sc.NextInt();
            U[i] = sc.NextChar();
        }

        var up = new List<int>();
        var down = new List<int>();
        var right = new List<int>();
        var left = new List<int>();
        for (int i = 0; i < N; i++)
        {
            if (U[i] == 'U') up.Add(i);
            if (U[i] == 'D') down.Add(i);
            if (U[i] == 'R') right.Add(i);
            if (U[i] == 'L') left.Add(i);
        }

        Ans = long.MaxValue;

        // 正面衝突

        #region 正面衝突

        {
            // U,D
            // Xが同じ && DのY > UのY
            var map = new Dictionary<long, List<(long y, bool up)>>();
            foreach (int i in up)
            {
                if (!map.TryGetValue(X[i], out _)) map[X[i]] = new List<(long y, bool up)>();
                map[X[i]].Add((Y[i], true));
            }

            foreach (int i in down)
            {
                if (!map.TryGetValue(X[i], out _)) map[X[i]] = new List<(long y, bool up)>();
                map[X[i]].Add((Y[i], false));
            }

            foreach (var pair in map)
            {
                var ls = pair.Value;
                ls.Sort((l, r) => l.y.CompareTo(r.y));
                long lastUp = long.MinValue;
                foreach ((long y, bool up) t in ls)
                {
                    if (t.up)
                    {
                        lastUp = t.y;
                    }
                    else
                    {
                        if (lastUp != long.MinValue) Ans = Math.Min(Ans, (t.y - lastUp) * 5);
                    }
                }
            }
        }

        {
            // l,r
            // Yが同じ
            var map = new Dictionary<long, List<(long x, bool r)>>();
            foreach (int i in right)
            {
                if (!map.TryGetValue(Y[i], out _)) map[Y[i]] = new List<(long x, bool r)>();
                map[Y[i]].Add((X[i], true));
            }

            foreach (int i in left)
            {
                if (!map.TryGetValue(Y[i], out _)) map[Y[i]] = new List<(long x, bool r)>();
                map[Y[i]].Add((X[i], false));
            }

            foreach (var pair in map)
            {
                var ls = pair.Value;
                ls.Sort((l, r) => l.x.CompareTo(r.x));
                long lastRight = long.MinValue;
                foreach ((long x, bool up) t in ls)
                {
                    if (t.up)
                    {
                        lastRight = t.x;
                    }
                    else
                    {
                        if (lastRight != long.MinValue) Ans = Math.Min(Ans, (t.x - lastRight) * 5);
                    }
                }
            }
        }

        #endregion

        // L字

        // 45度の位置にある
        {
            // d or left
            var dl = new Dictionary<long, List<(long x, bool d)>>();
            foreach (int i in down)
            {
                long s = X[i] + Y[i];
                if (!dl.TryGetValue(s, out _)) dl[s] = new List<(long x, bool d)>();
                dl[s].Add((X[i], true));
            }

            foreach (int i in left)
            {
                long s = X[i] + Y[i];
                if (!dl.TryGetValue(s, out _)) dl[s] = new List<(long x, bool d)>();
                dl[s].Add((X[i], false));
            }

            // xでソート
            foreach (var pair in dl)
            {
                var ls = pair.Value;
                ls.Sort((l, r) => l.x.CompareTo(r.x));
                long lastDown = long.MinValue;
                foreach (var t in ls)
                {
                    if (t.d) lastDown = t.x;
                    else
                    {
                        if (lastDown != long.MinValue) Ans = Math.Min(Ans, (t.x - lastDown) * 10);

                        #if DEBUG
                        if (Ans == -100)
                        {
                            Console.WriteLine("dl");
                        }
                        #endif
                    }
                }
            }
        }

        {
            // u or r
            var ur = new Dictionary<long, List<(long x, bool u)>>();
            foreach (int i in up)
            {
                long s = X[i] + Y[i];
                if (!ur.TryGetValue(s, out _)) ur[s] = new List<(long x, bool d)>();
                ur[s].Add((X[i], true));
            }

            foreach (int i in right)
            {
                long s = X[i] + Y[i];
                if (!ur.TryGetValue(s, out _)) ur[s] = new List<(long x, bool d)>();
                ur[s].Add((X[i], false));
            }

            // xでソート
            foreach (var pair in ur)
            {
                var ls = pair.Value;
                ls.Sort((l, r) => r.x.CompareTo(l.x));
                long lastUp = long.MaxValue;
                foreach (var t in ls)
                {
                    if (t.u) lastUp = t.x;
                    else
                    {
                        if (lastUp != long.MaxValue) Ans = Math.Min(Ans, (lastUp - t.x) * 10);
                        
#if DEBUG
                        if (Ans == -100)
                        {
                            Console.WriteLine("ur");
                        }
#endif
                    }
                }
            }
        }

        {
            // u or left
            var ul = new Dictionary<long, List<(long x, bool d)>>();
            foreach (int i in up)
            {
                long s = X[i] - Y[i];
                if (!ul.TryGetValue(s, out _)) ul[s] = new List<(long, bool d)>();
                ul[s].Add((X[i], true));
            }

            foreach (int i in left)
            {
                long s = X[i] - Y[i];
                if (!ul.TryGetValue(s, out _)) ul[s] = new List<(long, bool d)>();
                ul[s].Add((X[i], false));
            }

            // xでソート
            foreach (var pair in ul)
            {
                var ls = pair.Value;
                ls.Sort((l, r) => l.x.CompareTo(r.x));
                long lastUp = long.MinValue;
                foreach (var t in ls)
                {
                    if (t.d) lastUp = t.x;
                    else
                    {
                        if (lastUp != long.MinValue) Ans = Math.Min(Ans, (t.x - lastUp) * 10);
                        
#if DEBUG
                        if (Ans == -100)
                        {
                            Console.WriteLine("ul");
                        }
#endif
                    }
                }
            }
        }

        {
            // d or r
            var dr = new Dictionary<long, List<(long x, bool d)>>();
            foreach (int i in down)
            {
                long s = X[i] - Y[i];
                if (!dr.TryGetValue(s, out _)) dr[s] = new List<(long, bool d)>();
                dr[s].Add((X[i], true));
            }

            foreach (int i in right)
            {
                long s = X[i] - Y[i];
                if (!dr.TryGetValue(s, out _)) dr[s] = new List<(long, bool d)>();
                dr[s].Add((X[i], false));
            }

            // xでソート
            foreach (var pair in dr)
            {
                var ls = pair.Value;
                ls.Sort((l, r) => r.x.CompareTo(l.x));
                long lastDown = long.MaxValue;
                foreach (var t in ls)
                {
                    if (t.d) lastDown = t.x;
                    else
                    {
                        if (lastDown != long.MaxValue) Ans = Math.Min(Ans, (lastDown - t.x) * 10);
                        
#if DEBUG
                        if (Ans == -100)
                        {
                            Console.WriteLine("dr");
                        }
#endif
                    }
                }
            }
        }

        Console.WriteLine(Ans == long.MaxValue ? "SAFE" : Ans.ToString());
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 120380